Fuck it if you have a debian linux box you can use this for creating the apache
vhost container from a shell command. If you have other linux quite easy to
adapt so that it will work.
Code:
#!/bin/sh
# --(( Apache VirtualHost Configuration Tool v1.0 ))--
#
# Hans Waasdorp [email protected]
#
# Vhost is a very simple shell script to easily add virtual hosts to an
# Apache webserver. It prompts for a domain name and root directory,
# appends a virtual host entry to httpd.conf, and restarts Apache.
# variables - edit these to fit your environment
CONF=/etc/apache2/vhost.conf # location of Apache conf file
[email protected] # email appended to server errors,etc.
INDEX1=index.html # default index file
INDEX2=index.php # alternate index file
PID=/var/run/apache2.pid # location of httpd.pid
# Don't edit anything below
SERVER="$1"
DOCROOT="$2"
USER="$3"
IP="$4"
if [ ! "$*" ]
then
echo
echo " --(( Apache VirtualHost Configuration Tool v1.0 ))--"
echo
echo " Usage: vhost [domain] [webroot] [username] [ipaddress]"
echo
echo " domain = yourdomain.com (leave out www)"
echo " webroot = path to website directory, i.e. /home/username/www/yourdomain.com"
echo " username = your username"
echo " ipaddress = ipaddress to use for vhost"
echo
exit 1
fi
if [ -e "$CONF" ]
then
cp $CONF $CONF.bak
else
echo "No changes made - vhost.conf file not found!"
exit 1
fi
echo "
<VirtualHost $IP>
ServerAdmin $EMAIL
ServerName $SERVER
ServerAlias www.$SERVER
DocumentRoot $DOCROOT
DirectoryIndex $INDEX1 $INDEX2
ErrorLog /var/log/apache2/vhosts/$SERVER.error.log
CustomLog /var/log/apache2/vhosts/$SERVER.access.log combined
<Directory />
Options -Indexes +FollowSymLinks
AllowOverride None
Order allow,deny
allow from all
</Directory>
<Directory $DOCROOT>
Options All -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
" >> $CONF
mkdir -p $DOCROOT
chown -R $USER:$USER $DOCROOT
if [ -e "$PID" ]
then
kill -HUP `cat $PID`
echo
echo "- added VirtualHost to vhost.conf"
echo "- old vhost.conf renamed to vhost.conf.bak"
echo "- restarted Apache"
echo
exit 0
else
echo "Couldn't restart Apache - apache2.pid not found!"
exit 1
fi