Created
March 19, 2017 12:26
-
-
Save milanchheda/39161a33104a43ffc72837a70b8d7cb5 to your computer and use it in GitHub Desktop.
A simple shell script to add a new virtual host on Ubuntu machine.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create configuration file for the new virtual host in `sites-available` folder | |
sudo cat <<EOF >/etc/apache2/sites-available/$1.conf | |
<VirtualHost $2:80> | |
DocumentRoot "/var/www/html/$1/" | |
ServerName $2 | |
<Directory "/var/www/html/$1/"> | |
allow from all | |
order allow,deny | |
# Enables .htaccess files for this site | |
AllowOverride All | |
</Directory> | |
# Other directives here | |
</VirtualHost> | |
EOF | |
# Enable the newly added configuration file for the new virtual host | |
sudo a2ensite $1.conf | |
# Reload apache2 service | |
sudo service apache2 reload | |
# Add the new virtual host URL to `/etc/hosts` | |
sudo echo "127.0.0.1 $2" >> /etc/hosts | |
# Restart apache2 service | |
sudo service apache2 restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
bash adding_virtual_host.sh project-folder-name project-url