Return to Snippet

Revision: 41306
at February 16, 2011 01:23 by theriddlebrothers


Initial Code
#!/bin/bash
VHOST_CONF=/etc/httpd/conf/httpd-vhosts.conf
ROOT_UID=0
E_NOTROOT=87
WWW_ROOT=/var/www/vhosts

# Run as root
if [ "$UID" -ne "$ROOT_UID" ]
then
  echo "Must be root to run this script."
  exit $E_NOTROOT
fi

if [ -n "$1" ]
# Test whether command line present
then
  DOMAIN=$1
else
  echo "You must provide a full domain name for this site, i.e. 'mysite.domain.net'."
  exit
fi

# create site folder
mkdir $WWW_ROOT/$DOMAIN
mkdir $WWW_ROOT/$DOMAIN/public_html
chown riddleftp:ftp-users $WWW_ROOT/$DOMAIN -R

CONF=""
#echo $CONF >> $VHOST_CONF

CONF="\n\n##################\n# $DOMAIN\n##################\n<VirtualHost *:80>\n    DocumentRoot \"$WWW_ROOT/$DOMAIN/public_html\"\n    ServerName $DOMAIN\n</VirtualHost>\n"
echo -e $CONF >> $VHOST_CONF

apachectl restart

Initial URL

                                

Initial Description
Add an Apache virtual host via command line. Run as ./create mysite.domain.com

Initial Title
Virtual Hosts Creator

Initial Tags
apache

Initial Language
Bash