Created
November 16, 2012 09:04
-
-
Save turbod/4085669 to your computer and use it in GitHub Desktop.
Generate apache vhosts in UNIX (os x) system.
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/extra/httpd-vhosts.conf | |
ROOT_UID=0 | |
NOTROOT=87 | |
WWW_ROOT=/Volumes/Storage/norbi/www/ | |
# owner of the site directory | |
WEBUSER=$SUDO_USER | |
# echo "current user: $SUDO_USER" | |
# 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 | |
# check is the directory is exist | |
if [ ! -d "${WWW_ROOT}$DOMAIN" ]; then | |
# create document root site folder | |
su $WEBUSER -c "mkdir -p ${WWW_ROOT}$DOMAIN" | |
fi | |
CONF="\n\n# $DOMAIN \n<VirtualHost *:80>\n\tServerName $DOMAIN.localhost\n\tDocumentRoot ${WWW_ROOT}$DOMAIN\n\n\n\t<Directory \"/\">\n\t\tAllowOverride All\n\t\tAllow from all\n\t</Directory>\n\n\tErrorLog \"/private/var/log/apache2/$DOMAIN-error_log\"\n\tCustomLog \"/private/var/log/apache2/$DOMAIN-access_log\" common\n</VirtualHost>" | |
echo $CONF >> $VHOST_CONF | |
sudo apachectl restart | |
echo 'Done...' | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment