Using Local VirtualHosts On Apache 2.0.x

I decided to revisit one of my older posts; Setting Up Multiple Apache Local Web Sites On Your Computer; which was written as a guideline for Apache 1.3.x for both Linux and Windows machines.

I’ve always used Apache 1.3.x for my web development needs (yeah, I’m old school), but this time around though, I need to get some testing done Apache 2.0.x because it’s what one of the server I’m developing for runs.

After downloading the necessary Windows installer for Apache 2.0.x (yes, I’m assigned a Windows XP notebook at work) one thing I discovered almost immediately is that the tips I’ve mentioned in my earlier post doesn’t work on Apache 2.0.x right off the bat.

After reading some of the comments in my original post, as well as reading through the Apache 2.0 manual, and bouts of experimenting I found out that the following changes are necessary for VirtualHosts to work properly:

  1. Define the NameVirtualHost* directive: If this line is commented or non-existant in httpd.conf, your local VirtualHosts won’t work
  2. Include the hostname in the VirtualHost container. For example: <VirtualHost localtest>. If you want the VirtualHost to listen to other ports, use this example (of listening to port 8080): <VirtualHost localtest:8080>

That’s pretty much it. Migrating my Apache 1.3.x sites to Apache 2.0.x was a breeze.

13 responses to “Using Local VirtualHosts On Apache 2.0.x”.

  1. Setting Up Multiple Apache Local Web Sites On Your Computer - HTNet Says:

    […] Update: This guide is for Apache 1.3.x. To get local VirtualHosts to work with Apache 2.0.x, please click here. […]

  2. Phillip Plante Says:

    I want to have multiple web pages being served under apache 2.2 but everything I’ve tried to do with httpd seems not to work 403 error denied on the site or just serves the orginal page. This includes your advice on how to do this also. Can you help me resolve this problem please. I can email you my httpd to look at if it helps. Thanks for your time Phillip

  3. Tom Says:

    To Phillip: Try checking your firewall settings and make sure you have port 80 open. I had problems with 403 error even trying to connect to localhost as well as other computers on the network (Windows).

  4. Tom Says:

    To Phillip: Little late but might help other people. Try checking your firewall settings and make sure you have port 80 open. I had problems with 403 error even trying to connect to localhost as well as other computers on the network (Windows).

  5. David Says:

    I run Apache 2.0 on Windows XP and I don’t have to do either of those. I just do this:

    ServerName …

    And it seems to work just fine.

  6. erik Says:

    i tried your additions and no go. i can email httpd.conf if u have time to look at it. i had one site working and now i’ve added another and neither work and apache won’t load. error log says:
    NameVirtualHost *:80 has no VirtualHosts
    [Fri Jun 12 13:26:00 2009] [warn] VirtualHost overlaps with VirtualHost, the first has precedence, perhaps you need a NameVirtualHost directive
    [Fri Jun 12 13:26:00 2009] [warn] NameVirtualHost *:80 has no VirtualHosts
    thanks if u can help.

  7. erik Says:

    oh yes apache 2.x xp pro

  8. Site Admin Azmeen Says:

    Sure erik… email it to me: azmeen[at]

  9. erik Says:

    got it to work ..but what if i only want to test one php file in a vhost site do i do that. i’ve tried http://ec.localhost/tables.php and i get a 404?? no index.php or index.html in site. is that the problem. it’s just a site to test files.

  10. Site Admin Azmeen Says:

    It doesn’t matter if you got an index file or not. If you can’t open tables.php and you’re 100% sure it’s in the DocumentRoot; the only obvious answer is that Apache is misconfigured.

    Check your logs.

  11. Julius Says:

    I’m using moodle website with apache,mysql,php. First,trying to install to my localhost as test site. What I’m trying to do is to insert another moodle site inside to my first install. I put another name in “C:WINDOWS/hosts/” that is localhost1 after that since we all know after installation automatically when you browse it in a browser the address is localhost that’s default right?. Now I put localhost1 and try to run apache. Before the run there is a message after a test by httpd.conf an error but no specific location were to edit that. When I try to open the browser an ERROR 403 appeared both localhost and localhost1… IDEA? HELP ME PLEASE

  12. Roguefoxx Says:

    Thanks, this was very useful. I always just used additional directories in my DocumentRoot and this will come in handy. Tested and worked great!

  13. wampire Says:

    When I did the 1.3 tutorial, everything went to a single site.

    After doing this one, every site just kicked back to wampserver homepage.