Last active
August 29, 2015 14:21
-
-
Save davit/b5489ad4ea3a5da3df7b to your computer and use it in GitHub Desktop.
Creates a virtual host for a given domain
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 | |
domain=$1 | |
serverRoot=$2 | |
createRootFolder=$3 | |
vhostPath=/etc/apache2/sites-available/ | |
vhostFile=${domain}.conf | |
function print_usage { | |
echo "USAGE: create-vhosts [some-domain.com] [path/to/server/root/folder] [OPTIONAL: create the server folder]" | |
exit 0; | |
} | |
if [[ $# -eq 0 ]] ; then | |
print_usage | |
fi | |
if [ -z "${createRootFolder}" ]; then | |
: | |
else | |
documentRoot=${serverRoot}/${domain}/public_html | |
mkdir -p ${documentRoot} | |
touch ${documentRoot}/index.html | |
echo "<html> <body> <h1> Welcome to: ${domain} </h2> </body> </html>" > ${documentRoot}/index.html | |
fi | |
echo "<VirtualHost *:80> | |
ServerAdmin admin@${domain} | |
DocumentRoot \"${serverRoot}/${domain}/public_html\" | |
ServerName ${domain} | |
ServerAlias www.${domain} | |
ErrorLog \"/var/log/httpd/${domain}-error_log\" | |
CustomLog \"/var/log/httpd/${domain}-access_log\" common | |
</VirtualHost>" > ${vhostPath}/${vhostFile} | |
echo "Include ${vhostPath}/${vhostFile}" >> /etc/httpd/conf/httpd.conf | |
sed -i "s/#End of file/127.0.0.1 ${domain}\n#End of file/" /etc/hosts | |
/etc/init.d/apache2 restart | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment