Skip to content

Instantly share code, notes, and snippets.

@obiPlabon
Created December 23, 2015 20:22
Show Gist options
  • Save obiPlabon/e8e1f2ea300d47ac3528 to your computer and use it in GitHub Desktop.
Save obiPlabon/e8e1f2ea300d47ac3528 to your computer and use it in GitHub Desktop.
#!/bin/bash
hostName=$1
echo "$hostName creation procedure starts"
# create directory at /var/www/
sudo mkdir /var/www/$hostName
# goto apache dirctory
cd /etc/apache2/sites-available
# create config file
sudo touch $hostName.conf
sudo chmod 0777 $hostName.conf
# write virtual host config
echo -e "<VirtualHost *:80>\n\tServerName $hostName\n\tDocumentRoot /var/www/$hostName\n\tErrorLog ${APACHE_LOG_DIR}/error.log\n</VirtualHost>" > $hostName.conf
# Enabled this site
sudo a2ensite $hostName
# Restart apache after enabling this site
# so that everything works perfectly as expected
sudo service apache2 restart
sudo echo -e "127.0.0.1\t$hostName" >> /etc/hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment