Last active
August 29, 2015 14:12
-
-
Save wouterds/f64b1e981300756f41fa to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
VHOST_CONF=/etc/apache2/sites-available/ | |
ROOT_UID=0 | |
NOTROOT=87 | |
WWW_ROOT=/var/www/ | |
# owner of the site directory | |
WEBUSER=www-data | |
# check if is root | |
if [ "$UID" -ne "$ROOT_UID" ] | |
then | |
echo "You must be root to run this script." | |
exit $NOTROOT | |
fi | |
if [ -n "$1" ] | |
then | |
DOMAIN=$1 | |
else | |
echo "You must provide a full domain name for this site, i.e. ‘example.com’ " | |
echo -n "Run this script like ./a2createsite example.com" | |
exit | |
fi | |
# create document root site folder | |
su $WEBUSER -c "mkdir -p ${WWW_ROOT}www.$DOMAIN/public_html" | |
# vhost file content | |
# rewrite mod must be enabled | |
CONF="<VirtualHost *:80>\n\n\tServerName $DOMAIN\n\tServerAlias www.$DOMAIN\n\tDocumentRoot ${WWW_ROOT}www.$DOMAIN/public_html\n\n\t<Directory ${WWW_ROOT}www.$DOMAIN/public_html>\n\t\tOrder Deny,Allow\n\t\tAllow from all\n\t\tOptions FollowSymLinks Indexes\n\t</Directory>\n\n</VirtualHost>" | |
# write the vhost config file | |
echo -e $CONF > ${VHOST_CONF}www.$DOMAIN | |
# enable site configuration | |
cd $VHOST_CONF | |
a2ensite www.$DOMAIN > /dev/null | |
echo "www.$DOMAIN was created. In 5 seconds your apache will be reloaded" | |
sleep 5 | |
/etc/init.d/apache2 reload | |
echo "Done" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment