Skip to content

Instantly share code, notes, and snippets.

@Spuffynism
Created May 21, 2018 22:48
Show Gist options
  • Select an option

  • Save Spuffynism/69beca01cc234238a1ef87fb2a59a683 to your computer and use it in GitHub Desktop.

Select an option

Save Spuffynism/69beca01cc234238a1ef87fb2a59a683 to your computer and use it in GitHub Desktop.
Creates a virtual host
if [[ $# -eq 0 ]] ; then
echo 'You must specify a valid virtual host name'
exit 0
fi
vhost=$1
export vhost
sudo mkdir -p /var/www/"$vhost"/public_html
sudo chmod -R 777 /var/www/"$vhost"
sudo -E bash -c 'echo -e "<?php phpinfo();" > /var/www/$vhost/public_html/index.php'
sudo -E bash -c 'echo -e "<VirtualHost *:80>
ServerAdmin admin@$vhost
ServerName $vhost
ServerAlias www.$vhost
DocumentRoot /var/www/$vhost/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>" > /etc/apache2/sites-available/$vhost.conf'
sudo a2ensite "$vhost".conf
sudo service apache2 restart
sudo -E bash -c 'echo -e "127.0.0.1 $vhost" >> /etc/hosts'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment