Configuring httpd-vhosts.conf

Using Notepad++, open C:\wamp\bin\apache\Apache2.2.11\conf\extra\httpd-vhosts.conf.

You should see something very similar to this:

#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.localhost
    DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/docs/dummy-host.localhost"
    ServerName dummy-host.localhost
    ServerAlias www.dummy-host.localhost
    ErrorLog "logs/dummy-host.localhost-error.log"
    CustomLog "logs/dummy-host.localhost-access.log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.localhost
    DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/docs/dummy-host2.localhost"
    ServerName dummy-host2.localhost
    ErrorLog "logs/dummy-host2.localhost-error.log"
    CustomLog "logs/dummy-host2.localhost-access.log" common
</VirtualHost>

What you want to do is add VirtualHost blocks that will point to your local websites.  No need to be fancy here, just these two line blocks should do the trick.  For esoteric reasons, it is recommended you keep the localhost block at the top of the line.  By the way, these two liners seem to do just fine without quotation marks.

<VirtualHost *:80>
DocumentRoot C:/wamp/www/drupal-6.12
ServerName localhost
</VirtualHost>

<VirtualHost *:80>
DocumentRoot C:/wamp/www/drupal-6.12
ServerName www.mysite1.com
</VirtualHost>

<VirtualHost *:80>
DocumentRoot C:/wamp/www/drupal-6.12
ServerName www.mysite2.com
</VirtualHost>

<VirtualHost *:80>
DocumentRoot C:/wamp/www/drupal-6.12
ServerName www.mysite3.com
</VirtualHost>

Your new file should look like this:

#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#

<VirtualHost *:80>
DocumentRoot C:/wamp/www/drupal-6.12
ServerName localhost
</VirtualHost>

<VirtualHost *:80>
DocumentRoot C:/wamp/www/drupal-6.12
ServerName www.mysite1.com
</VirtualHost>

<VirtualHost *:80>
DocumentRoot C:/wamp/www/drupal-6.12
ServerName www.mysite2.com
</VirtualHost>

<VirtualHost *:80>
DocumentRoot C:/wamp/www/drupal-6.12
ServerName www.mysite3.com
</VirtualHost>

I once copied a set of blocks that look very similar to these VirtualHost blocks from the Drupal site.  I did not notice that the closing tags were missing a forward slash.  Guess what?  The blocks did not work and it took me quite a few hours to recognize what was right under my nose.  Copy and paste if you must, but try to understand what's going on at the same time.  That's my advice.

At this point you may be wondering where mysite1, mysite2 and mysite3 may be located in your directory structure.  

It's like this:

C:\wamp\www\drupal-6.12\sites\www.mysite1.com
C:\wamp\www\drupal-6.12\sites\www.mysite2.com
C:\wamp\www\drupal-6.12\sites\www.mysite3.com

Look for the following notes in the default settings file at C:\wamp\www\drupal-6.12\sites\default\default.settings.php:

* The configuration file to be loaded is based upon the rules below.
 *
 * The configuration directory will be discovered by stripping the
 * website's hostname from left to right and pathname from right to
 * left. The first configuration file found will be used and any
 * others will be ignored. If no other configuration file is found
 * then the default configuration file at 'sites/default' will be used.
 *
 * For example, for a fictitious site installed at
 * http://www.drupal.org/mysite/test/, the 'settings.php'
 * is searched in the following directories:
 *
 *  1. sites/www.drupal.org.mysite.test
 *  2. sites/drupal.org.mysite.test
 *  3. sites/org.mysite.test
 *
 *  4. sites/www.drupal.org.mysite
 *  5. sites/drupal.org.mysite
 *  6. sites/org.mysite
 *
 *  7. sites/www.drupal.org
 *  8. sites/drupal.org
 *  9. sites/org
 *
 * 10. sites/default

It is important to understand these comments in order to be able to properly set up a multisite Drupal environment.  Once you begin to step through the Drupal files, starting with index.php, using the Eclipse debugger, things will become clearer.  I promise.



About Kipp Elliott Watson

Kipp Elliott Watson is a Drupaler (Drupalista?) who lives in Northern New Jersey and subscribes enthusiastically to the principles that have helped broaden Drupal's community and have brought Drupal to the forefront of the CMS revolution.  He is occasionally available for Drupal projects and would love to hear from you if you need a Drupal consultant.  His resume can be viewed and downloaded here.  

If you would like to learn about the Ideal Drupal Development Environment, visit: http://sites.google.com/site/theidealdrupalenvironment/

If you would like to add a Google Wave to a fresh Drupal installation, visit:

Drupal Developer for Hire

Looking to hire a Drupal Developer? Email me at Kipp period Watson at gmail period com. Just mention this website, so I'll know where you're coming from!