Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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}$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}$DOMAIN/public_html\n\n\t<Directory ${WWW_ROOT}$DOMAIN/public_html>\n\t\tOrder Deny,Allow\n\t\tAllow from all\n\t\tOptions -Indexes\n\t</Directory>\n\n</VirtualHost>"
- # write the vhost config file
- echo -e $CONF > ${VHOST_CONF}$DOMAIN
- # enable site configuration
- cd $VHOST_CONF
- a2ensite $DOMAIN > /dev/null
- echo "$DOMAIN was created. In 5 seconds your apache will be reloaded"
- sleep 5
- /etc/init.d/apache2 reload
- echo "Done"
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement