Skip to content

Instantly share code, notes, and snippets.

@svandragt
Created September 13, 2016 09:25
Show Gist options
  • Save svandragt/6d1c80d6c8e58e85b94595653fb4c772 to your computer and use it in GitHub Desktop.
Save svandragt/6d1c80d6c8e58e85b94595653fb4c772 to your computer and use it in GitHub Desktop.
add virtual host
#!/bin/bash
# version 1.0.0 - 21 march 2012
echo "Enter Hostname:"
read AVS_HOSTNAME
echo
echo "Enter webmaster email for '${AVS_HOSTNAME}':"
read AVS_WEBMASTER
echo
echo "Generating directories in ${HOME}/projects/${AVS_HOSTNAME}..."
mkdir $HOME/projects/$AVS_HOSTNAME/public -p
mkdir $HOME/projects/$AVS_HOSTNAME/logs
echo "Hello World! Another site saved." | tee $HOME/projects/$AVS_HOSTNAME/public/index.html
echo
echo "Generating virtual host file:"
echo "
<VirtualHost *:80>
ServerAdmin ${AVS_WEBMASTER}
ServerName ${AVS_HOSTNAME}
DocumentRoot ${HOME}/projects/${AVS_HOSTNAME}/public/
ErrorLog ${HOME}/projects/${AVS_HOSTNAME}/logs/error.log
CustomLog ${HOME}/projects/${AVS_HOSTNAME}/logs/access.log combined
</VirtualHost>
" | sudo tee /etc/apache2/sites-available/$AVS_HOSTNAME
echo "Virtual Host file saved to /etc/apache2/sites-available/${AVS_HOSTNAME}"
echo "Enabling site and reloading apache..."
sudo a2ensite $AVS_HOSTNAME
sudo service apache2 reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment