Virtual Hosts in Apache 2.2

Posted on December 4, 2006. Filed under: Hacks |

I installed apache 2.2 in c:/program files/apache software foundation/apache2.2.  The default domain was, and the default website was

I needed to add a virtual host, like, and I needed the document root for that site to be in some other folder, other than c:/program files/…/htdocs.  I needed it to be in c:/www/docs/sites/mysite.

First off, in C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf, at the very bottom, there are these two lines:

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

What I do is remove the comment from the second line.

Then I open the httpd-vhosts.conf file… this is what I do to it.  Compare this with what you have in your vhosts.conf file.

# 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.
    DocumentRoot /www/docs/sites/mysite
    ErrorLog logs/
    CustomLog logs/ common

#<VirtualHost *:80>
#    ServerAdmin
#    DocumentRoot /www/docs/
#    ServerName
#    ErrorLog logs/
#    CustomLog logs/ common

Finally, I go back to the httpd.conf file and add a Directory directive just below the Directory directive for htdocs and above the IfModule dir_module.

<Directory “C:/www/docs/sites”>
 Order allow,deny
 Allow from all

I create a dummy index.html in c:/www/docs/sites/mysite, and restart apache:

net stop apache2.2

net start apache2.2

Then I open my hosts file, from c:\windows\system32\drivers\etc in notepad and add these two lines.

here is my computers ip. you can set it and you will see it work on your pc.

I open my browser and say and I see the results from the new folder.


Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

  • Posts


  • Blog Stats

    • 78 hits
  • Meta Information

Liked it here?
Why not try sites on the blogroll...

%d bloggers like this: