Adding vhosts to Apache, the scripted way

This script adds a directory in /var/www and a vhost file in /etc/apache2/sites-available. Tested on Debian and Ubuntu.


#!/bin/bash

# usage $ sudo ./addvhost.sh mydomain.com

/bin/mkdir /var/www/$1

/bin/echo ‘
<VirtualHost *>
ServerAdmin webmaster@localhost
ServerName ‘$1′
DocumentRoot /var/www/’$1′
ErrorLog /var/log/apache2/’$1′-error.log
LogLevel warn
CustomLog /var/log/apache2/’$1′-access.log combined
ServerSignature On
</VirtualHost>
‘ > /etc/apache2/sites-available/$1

/bin/ln -s /etc/apache2/sites-available/$1 /etc/apache2/sites-enabled/$1

Leave a Reply

Why ask?