Introduction: Installing a New Virtual Host in the Apache Web Server

About: Glia - Equal Care

The purpose of this tutorial is to walk through the process of configuring and initiating a new Apache web server virtual host. A virtual host is a "profile" that detects which DNS host (e.g., is being called for at any given IP address. It is possible to narrow this further by only coupling IP addresses and hostnames in the virtual host configuration, but I will skip that and assume that every IP address the server has is permitted to access the virtual host.

This instructable was made specifically with a Debian server running Apache 2.2.x.

Step 1: Login and Get to the Right Place

First, log in and change directories to your configuration directory. In most sane servers, this means logging in as a user with superuser privileges, and going somewhere in /etc/

$ ssh
Password: exciting_password
~$ cd /etc/apache2/sites-available

Step 2: Create the Virtualhost From a Default Template

Usually I keep a default file around, which I copy to a clipboard and paste for use. From that default file, you can edit the specifics. Below is a reasonable default file you can refer to, which assigns the document to a Drupal directory:

$ pico

<VirtualHost *:80>
DocumentRoot /home/web/drupal/drupal-6
ServerAlias *
RewriteEngine On
RewriteOptions inherit
CustomLog /var/log/apache2/MyOtherHostname.log combined

Needless to say, you can make whatever customizations you wish according to the information found in the Apache 2.2 virtual host documentation.

Step 3: Enable the Site and Restart Your Server

Now it's time to enable the site and restart the server. Debian has a few cool server management tricks here:

First, let's enable the site:

$ sudo a2ensite
Site installed; run /etc/init.d/apache2 reload to enable.

$ sudo /etc/init.d/apache2 reload
Reloading web server config.... PID#

And now you should be able to access the site so long as the DNS server points it to your server.

For Drupal sites, I often take this opportunity to add the cron.php file to my crontab before I forget:

$ sudo pico /etc/cron.d/drupal
2 0,5,10,15,20 * * 1-6 nobody curl --silent

That's it! Congratulations!

tarek : )