View Single Post
Old 07-16-2007, 07:37 AM  
ServerGenius
Confirmed User
 
Join Date: Feb 2002
Location: Amsterdam
Posts: 9,377
Apache vhost tool once again.....i forgot to build in a check before creating
the new vhost docroot.

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


if [ ! -d "$DOCROOT" ]
        then
                echo "Creating vhost docroot"
                mkdir -p $DOCROOT
                chown -R $USER:$USER $DOCROOT
        else
                exit 1
fi

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
__________________
| http://www.sinnerscash.com/ | ICQ: 370820 | Skype: SinnersCash | AdultWhosWho |

Last edited by ServerGenius; 07-16-2007 at 07:40 AM..
ServerGenius is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote