I use a script from
http://commandlineidiot.com which I have modified to fit my needs. It just adds domains, but I have been meaning to add a function to remove domains.
Code:
#! /bin/bash
#
# =======================
# Siteup Script 0.5
# Written by Command Line Idiot
# http://commandlineidiot.com
# You may use, modify, and redistribute this script freely
# Released: August 2007
# Modified by Josh Price
# Re-Release: July 2012
# =======================
# =======================
# Root check
# =======================
# init
FILE="/tmp/out.$$"
GREP="/bin/grep"
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# End Root Check
# =======================
# set functions
# =======================
# make_index is the function to create a basic index.html file
# within the documents directory of the new domain. The variable
# for domain name is passed into the file at $dname. You can alter
# any of the code between the terms _EOF_ and it will be reflected
# in the index.html file.
function make_index
{
cat <<- _EOF_
<html>
<head><title>$dname</title></head>
<body>$dname Coming Soon.</body>
</html>
_EOF_
}
# =======================
# End make_index
# =======================
# make_vhost is the function to create a config file that
# Apache2 can interpret. The variable for the domain name is passed
# into the file at $dname, and the system-wide variable for username
# is passed into the file at $USER. You may wish to replace the
# ServerAdmin email address with your own email address. You may alter
# any of the code between the terms _EOF_ to build your own preferred
# standard config file.
function make_vhost
{
cat <<- _EOF_
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin support@$dname
ServerName www.$dname
ServerAlias $dname
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /home/USERNAME/sites/$dname/public_html
# Log file locations
LogLevel warn
ErrorLog /home/USERNAME/sites/$dname/log/error.log
CustomLog /home/USERNAME/sites/$dname/log/access.log combined
</VirtualHost>
_EOF_
}
# =======================
# header
# =======================
clear
echo "*** Site Setup ***"
# =======================
# set domain name variable
# =======================
echo -n "==> Enter new domain name (domain.com): "
read dname
echo "Setting up files for $dname"
# =======================
# create needed directories
# =======================
mkdir -vp /home/USERNAME/sites/$dname
mkdir -vp /home/USERNAME/sites/$dname/log
mkdir -vp /home/USERNAME/sites/$dname/public_html
touch /home/USERNAME/sites/$dname/log/access.log
echo "created /home/USERNAME/sites/$dname/log/access.log"
touch /home/USERNAME/sites/$dname/log/error.log
echo "created /home/USERNAME/sites/$dname/log/error.log"
# =======================
# build index file
# =======================
make_index > /home/USERNAME/sites/$dname/public_html/index.php
echo "created /home/USERNAME/sites/$dname/public_html/index.php"
# =======================
# build vhost config file
# =======================
make_vhost > /etc/apache2/sites-available/$dname
echo "created /etc/apache2/sites-available/$dname"
# =======================
# Add site to Apache
# =======================
a2ensite $dname
# =======================
# Restart Apache
# =======================
/etc/init.d/apache2 reload
# =======================
# exit
# =======================
echo "*** Finished setting up files for $dname. Goodbye!"
exit
Edit as you need. Replace USERNAME with your username.
You could easily add wordpress installation to this