Last active
December 20, 2015 17:19
-
-
Save devoto13/6168177 to your computer and use it in GitHub Desktop.
Shell-script for creating virtual hosts (with directory structure) for LAMP on Ubuntu.Place somewhere on the PATH, for example at /usr/local/bin.Usage: sudo addvhost <hostname> <branch>
This file contains hidden or 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
#!/bin/bash | |
if [ $# -lt 2 ] ; then | |
echo "Usage: sudo addvhost <hostname> <branch>"; | |
exit 0; | |
fi | |
email="[email protected]" | |
domain="$1" | |
branch="$2" | |
echo "Creating directories..." | |
mkdir -p /var/www/$domain/$branch | |
mkdir -p /var/www/$domain/log | |
echo "Creating vhost..." | |
echo "127.0.0.1 $domain.$branch www.$domain.$branch" >> /etc/hosts | |
touch /etc/apache2/sites-available/$domain.$branch | |
(cat <<VDOC | |
<VirtualHost *:80> | |
ServerName $domain.$branch | |
ServerAlias www.$domain.$branch | |
ServerAdmin $email | |
DocumentRoot /var/www/$domain/$branch | |
ErrorLog /var/www/$domain/log/$branch-error.log | |
CustomLog /var/www/$domain/log/$branch-access.log combined | |
</VirtualHost> | |
VDOC | |
) > /etc/apache2/sites-available/$domain.$branch | |
echo "Enabling vhost..." | |
a2ensite $domain.$branch | |
echo "Restarting Apache..." | |
service apache2 restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment