Installing a New Virtual Host in the Apache Web Server

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 : )

Be the First to Share


    • Unusual Uses Contest

      Unusual Uses Contest
    • Reclaimed Materials Contest

      Reclaimed Materials Contest
    • Made with Math Contest

      Made with Math Contest



    13 years ago

    Hey, this is a great instructable and is very informative. Just one thing is missing... pictures! It really helps a lot when trying to follow directions so you should consider taking some photographs. Once you do that and leave me a message when you have so that we can publish your work. Thanks! Thanks for the cool instructable and we hope to publish this soon!


    Reply 13 years ago on Introduction

    I'm actually not sure how photos would aid this particular instructable, except to make it a bit more pretty. Anyhow, pretty pictures inserted! : ) tarek : )


    ubuntu 10.04 has some gotchas with virtual hosts. Also had to change 000-default.


    FYI -- Apache 2.2 has a dummy vhosts-conf file in the /conf/extras directory that you can replicate and call from httpd.conf.

    The design minimizes the edit work in httpd.conf.