To automate adding new virtual hosts to Apache, create a new file in your text editor of choice:

Enter the following Bash script into the file:

Make the file executable:

Next create a skeleton file in your VHOSTDIR with the following contents:

The above script was written on an Ubuntu 12.04 system, so you may need to edit file paths for other systems. You’ll also probably want to edit the skeleton file to suit your own needs.

Check out our bash scripts repository for the files.