Setting Up Multiple Apache Local Web Sites On Your Computer

If you do web development on WAMP or LAMP, but not really adept in general network configurations, your typical local development web content might have URLs similar to as follows:

  • http://localhost/projecta
  • http://localhost/projectb
  • http://localhost/projectc
  • http://localhost/projectc-beta2

Wouldn’t it be nicer if those projects have URLs such as:

  • http://projecta
  • http://projectb
  • http://projectc
  • http://projectc-beta2

Continue reading on if you’re interested to find out how this can be achieved on both Windows and Linux computers. This writeup will cover setting up the hosts as well as configuring Apache (versions 1.3.x) to support the hosts.

This tutorial is designed for those who have administrative priviledges on the development computer (under Administrators group on Windows, or have root access for Linux). More often than not, if you’re not using a shared computer, you’ll most likely have such access.

Setting Up the Fake Hostnames

A Primer on Hostnames: Hostnames are names for computers connected on a network. For HTNet, its hostname is www.heritage-tech.net (and also heritage-tech.net). For the nitty-gritty details, please refer to Hostname on Wikipedia.

The fake hostnames such as projecta, projectb, projectc and projectc-beta2 can be set in either of these hosts configuration files (also referred to as hosts files) depending on your operating system:

  • For Windows: C:\WINDOWS\SYSTEM32\DRIVERS\ETC\HOSTS (assuming your Windows installation is in C:\WINDOWS).
  • For Linux: /etc/hosts

If you were to open these files in a text editor, you’ll see content similar to the following:

127.0.0.1        localhost
192.168.1.18     testhost.testdomain.com testhost

All hosts files will have the localhost entry which resolves to 127.0.0.1, also known as the loopback address. Basically, what the first line in the host file illustrated above tells us is to route all network packets addressed to localhost to the computer you’re using.

So to get our fake hostnames working, they each should have an entry resolving to 127.0.0.1 in your hosts file. Example as follows:

127.0.0.1        localhost
127.0.0.1        projecta
127.0.0.1        projectb
127.0.0.1        projectc
127.0.0.1        projectc-beta2
192.168.1.18     testhost.testdomain.com testhost

To test the configuration, you should ping the fake hosts and if you had followed the steps above correctly, you should get a response from 127.0.0.1 for the projecta, projectb, projectc and projectc-beta2 hosts. This concludes the host resolving section of this tutorial.

Configuring Apache

The next step involves configuring Apache to handle requests to the hosts defined above. To do this, you’ll need to edit your Apache installation’s configuration file; httpd.conf. On a default Apache for Windows installation, this file will be in C:\Program Files\Apache Group\Apache\conf\. For Linux, the location of the httpd.conf file usually depends on the distribution. On Slackware Linux, it’s in /etc/apache/.

Open the httpd.conf file in your favourite text editor and look for a line that starts with DocumentRoot. This line sets the location for the files that will be served as your default web site.

On Linux, it will look something like the following (Note that the actual location may differ on your setup):

DocumentRoot "/var/www/htdocs"

Whereas on Windows, it will be similar to (Note that the actual location may differ on your setup):

DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs"

Also note that for Windows, Apache can also use a normal slash (/) instead of the typical backslash (\) in the directory path. You should also enclose directory paths in quotes. From now on, we’ll refer to these directories as DocumentRoot.

If the directories where you want to serve content for the hosts created earlier reside within the DocumentRoot directory, you merely need to define a VirtualHost declaration for each of them. Let’s assume that the files for http://projecta will be in the directory named projecta under the DocumentRoot directory (which will be /var/www/htdocs/projecta/ for Linux or C:\Program Files\Apache Group\Apache2\htdocs\projecta\ for Windows).

Therefore, at the end of your httpd.conf file, append the following lines to create the projecta virtual host:

For Linux:

<VirtualHost *>
DocumentRoot /var/www/htdocs/projecta
ServerName slackbox
</VirtualHost>

For Windows:

<VirtualHost *>
DocumentRoot "C:/Program Files/Apache Group/Apache/htdocs/projecta"
ServerName slackbox
</VirtualHost>

If the files are served from a directory outside of the DocumentRoot, you need to create a Directory declaration for each of the directories in addition to the VirtualHost declaration.

For example, let’s assume that files from projectb will be served from /web/projectb (for Linux) or C:\web\projectb (for Windows). Therefore, the following lines should be appended to your httpd.conf file:

For Linux:

<Directory "/web/projectb">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>

<VirtualHost *>
DocumentRoot /web/projectb
ServerName projectb
</VirtualHost>

For Windows:

<Directory "C:\web\projectb">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>

<VirtualHost *>
DocumentRoot "C:\web\projectb"
ServerName projectb
</VirtualHost>

Testing the Setup

Once all of the above is done, you can now test your configuration. However, you need to restart the Apache service in order to apply the changes made above. Here’s how to do it if you’ve installed Apache as a service (9 times out of time, this is how it’s normally installed):

For Linux (distros using BSD-style init like Slackware):

/etc/rc.d/rc.httpd restart

For Linux (distros using sysv-style init like Red Hat):

service httpd restart

For Windows:

  1. Run: services.msc
  2. Look for Apache in the services list and select it
  3. Click the Restart Service button

If you’ve followed through this guide closely, you should now have a working Apache installation with multiple named local sites.

Was this guide useful for you? Please digg it or drop me a comment or two.

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

64 responses to “Setting Up Multiple Apache Local Web Sites On Your Computer”.

  1. mike Says:

    urm. confusing. I dont understand how to point it out of the whole apache folder, to a folder in my documents.

  2. Site Admin Azmeen Says:

    Hi mike,

    If you want to change the main web serving folder to a different location, it really is very simple. You say you want to point it to a folder in My Documents, so I assume you’re using Windows XP.

    The real path to My Documents is: C:\Documents and Settings\<Your Name>\My Documents\. So if you want to serve your web pages from a folder called “Webs” in My Documents, just set your DocumentRoot setting as follows:

    DocumentRoot "C:\Documents and Settings\<Your Name>\My Documents\Webs"

  3. A Ozkaya Says:

    Excellent straight to the point. Thanks ever so much

  4. Torjokim Says:

    Hi,

    I try to find out how to get my server on mye local computer to be similar to the one on the web..

    example:
    On the webserver where my homepage is:
    /home/triveran/public_html/

    On my local computer:
    C:\Programfiler\xampp\htdocs\homepage\

    this two has to be the same, because i use php on my page and some of these are pointing to a directory where i have to have with all the path… like /home/triveran/public_html/…

    anyone help me?
    Thanks

  5. Site Admin Azmeen Says:

    Hi Torjokim,

    Assuming you’re using a premade script (whether open source or otherwise), a properly designed one should have a configuration file to define the root directory.

    This is not an Apache-specific issue but more related to your script’s installation method.

    I suggest going through the manual or help file to determine where your root directory definition is stored.

    All the best.

  6. Danny Says:

    I have been trying this for quite some time, and been running into a problem. First of all, I am using WAMP 1.6.6 from wampserver.com

    I set up my hosts properly, I can ping them etc.

    I then set this up in my httpd.conf file:

    DocumentRoot “C:/wamp/www/__MY_PROJECTS__/test”
    ServerName test

    Now, whenever I load http://localhost/ it goes to the test directory. The same thing happens if I go to http://test/

    I also tried setting up multiple virtualhosts, and the server always displays the directory specified in the FIRST virtualhost that is in the httpd.conf file.

    Anyone know whats going on?

  7. Site Admin Azmeen Says:

    Hi Danny,

    When using NameVirtualHost on Apache, the first VirtualHost declaration will be used as the default web site. Here’s my httpd.conf’s VirtualHost section:

    NameVirtualHost *

    # Default Site
    <VirtualHost *>
    DocumentRoot “C:/Program Files/Apache Group/Apache/htdocs”
    ServerName PC064
    ErrorLog logs/default-error_log
    CustomLog logs/default-access_log common
    </VirtualHost>

    # Dev CMS
    <VirtualHost *>
    DocumentRoot “C:/Storage/devcms”
    ServerName devcms
    ErrorLog logs/devcms-error_log
    CustomLog logs/devcms-access_log common
    </VirtualHost>
    <Directory “C:/Storage/devcms”>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
    </Directory>

    #CI Dev Web
    <VirtualHost *>
    DocumentRoot “C:\Storage\devweb”
    ServerName devbox
    ErrorLog logs/devweb-error_log
    CustomLog logs/devweb-access_log common
    </VirtualHost>
    <Directory “C:/Storage/devweb”>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
    </Directory>

    #WP Test Web
    <VirtualHost *>
    DocumentRoot “C:\Storage\wordpress”
    ServerName wptest
    ErrorLog logs/wp-error_log
    CustomLog logs/wp-access_log common
    </VirtualHost>
    <Directory “C:\Storage\wordpress”>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
    </Directory>

    #MSSQL Web
    <VirtualHost *>
    DocumentRoot “C:\Storage\mssqlphp”
    ServerName mssqlphp
    ErrorLog logs/msphp-error_log
    CustomLog logs/msphp-access_log common
    </VirtualHost>
    <Directory “C:\Storage\mssqlphp”>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
    </Directory>

    #Mkt Inv Web
    <VirtualHost *>
    DocumentRoot “C:\Storage\mktinv”
    ServerName mktinv
    ErrorLog logs/mktinv-error_log
    CustomLog logs/mktinv-access_log common
    </VirtualHost>
    <Directory “C:\Storage\mktinv”>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
    </Directory>

    #MIS Inv Web
    <VirtualHost *>
    DocumentRoot “C:\Storage\misinv”
    ServerName misinv
    ErrorLog logs/misinv-error_log
    CustomLog logs/misinv-access_log common
    </VirtualHost>
    <Directory “C:\Storage\misinv”>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
    </Directory>

    Does yours look similar?

  8. TechMasala - Technology Spice Rack » Configuring Apache Locally Says:

    [...] that resembles production and will also help learn Apache. Here is a good article “Setting Up Multiple Apache Local Web Sites On Your Computer” that provides details of how to do [...]

  9. Joyce Babu Says:

    Hey,
    Thanks a lot for the article. I was searching for this for a long time. But, I am getting the same error Danny said above.
    Here is my conf file entry
    NameVirtualHost *

    DocumentRoot “C:/Apache2/htdocs/sitec”
    ServerName localsitea

    DocumentRoot “C:/Apache2/htdocs/siteb”
    ServerName localsiteb

    DocumentRoot “C:/Apache2/htdocs/sitea”
    ServerName localsitec

    Can you please help me?

    Thanks :)

  10. Joyce Babu Says:

    I got the answer, thankyou

  11. Saul Says:

    hey, can you tell me how did u fix the problem?? cuz i having the same, i have 2 virtual servers and both addresses go to the first virtual directory.

    thanks.

  12. papajoneh Says:

    mine working… yahooooo. Azmeen is the man. Salute forever!

  13. Robg Says:

    HI. I am having probs with Vhosts. I have it working at the moment on different ports. Ports redirected from 80 to 8000 and 9000. I added Listen 8000 and 9000 to main config. Both sites work fine. Though if i try to get them to respond when they are both on port 8000 it all ways opens the main site. I can ping the servers as it states in the hosts file no problem (e.g server1 server2 etc). httpd-vhosts and hosts file is below. Anyhelp would be good as my head is starting to hurt..lol

    NameVirtualHost *:8000

    DocumentRoot D:/server/xampp/htdocs
    ServerName server1:8000
    ServerAdmin admin@localhost

    ServerName server2:9000
    ServerAlias *.http://example.no-ip.info
    ServerAdmin admin@localhost
    DocumentRoot D:/server/xampp/htdocs/dt

    Options ExecCGI Includes FollowSymLinks
    Options +ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all

    ———————–
    127.0.0.1 localhost:80
    127.0.0.1 server1:8000
    127.0.0.1 server2:9000

  14. Site Admin Azmeen Says:

    Hi Robg,

    First of all, you should change your hosts file to the following:


    127.0.0.1 localhost
    127.0.0.1 server1
    127.0.0.1 server2

    Reason being, the ports should not be part of the definition.

    As for the virtual hosts settings, I’d use the following

    # Default Webby - Any requests not catched by a vhost goes here
    # Should be the FIRST vhost you define
    <VirtualHost *:80>
    DocumentRoot C:/path/to/default/site/files
    ServerName localhost
    ErrorLog logs/defaultsite-error_log
    CustomLog logs/defaultsite-access_log common
    </VirtualHost>


    # Server1 Settings
    <VirtualHost *:8000>
    DocumentRoot C:/path/to/server1/site/files
    ServerName server1
    ErrorLog logs/server1-error_log
    CustomLog logs/server1-access_log common
    </VirtualHost>


    # Server2 Settings
    <VirtualHost *:9000>
    DocumentRoot C:/path/to/server2/site/files
    ServerName server2
    ServerAlias example.no-ip.info # NOTE the format
    ErrorLog logs/server2-error_log
    CustomLog logs/server2-access_log common
    </VirtualHost>

    That should work for what you’re trying to achieve.

  15. Robg Says:

    Hi again. Used the coding. And yes you are a legend dude thankyou. I still cannot work out why i cannot use the same ports(for in future if i make more sites. I will have so many different ports for each site)
    thanx Rob

  16. Site Admin Azmeen Says:

    Robg,
    Actually, you can. How do you think a web hosting company hosts so many domains on one server? Virtual hosts of course! :)

    Let’s say you want server2 to also listen on port 8000, you just need to change it to:


    # Server2 Settings
    <VirtualHost *:8000>
    DocumentRoot C:/path/to/server2/site/files
    ServerName server2
    ServerAlias example.no-ip.info # NOTE the format
    ErrorLog logs/server2-error_log
    CustomLog logs/server2-access_log common
    </VirtualHost>

    All done and ready to run :)

    Glad to be of assistance.

  17. Robg Says:

    Hi,
    Hi, i know that. But if i change the port number to be the same as the main server, the main server responds. There is something wrong with the server responding by name.Thanx i anyhow i will just call by ports.
    Rob

  18. Robg Says:

    Hi
    Problem solved. It was the redirect. When accessing each site in the address bar all there was, was http://12345677:8000 instead of and actual site name like http://example.com
    Thankyou for your help
    Rob

  19. Site Admin Azmeen Says:

    Glad your resolved it.

  20. WanWave.Com Blog Says:

    [...] Setting Up Multiple Apache Local Web Sites On Your Computer [...]

  21. Mau Says:

    Thanks for the article/comments. Very useful info.

  22. Matt Says:

    Thanks so much for this. I’ve tried setting this up several times before, but was never able to get it working until now.
    Thanks again!

  23. Site Admin Azmeen Says:

    Mau and Matt,

    Glad it’s helpful in helping you :)

  24. user___ Says:

    Hi guys,
    I did what was written above but I get only my first subhost work and it does not seem to open ASP, PHP, etc. files(even HTML).

    It opens only images.

    I am running Apache 2 and my system is XP(Service Pack 2).

    BTW:When I ping the newly created hosts I get replies(When I shut down my firewall).

  25. Andrey Says:

    Thanks very much – I wanted to run my PHP scripts on my local machine.

  26. Jeff Says:

    To everyone who is having the problem where your first VirtualHost keeps coming up if you have multiple projects set up. You need to make sure that you have included the NameVirtualHost directive. Here’s an example of my files so that I got it to work:

    HOSTS File
    ——————————–
    127.0.0.1 localhost
    127.0.0.1 servera
    127.0.0.1 serverb
    127.0.0.1 serverc
    127.0.0.1 serverd

    HTTPD.CONF File
    ——————————–
    NameVirtualHost 127.0.0.1

    ServerName servera
    DocumentRoot “C:\WWW\servera”

    ServerName serverb
    DocumentRoot “C:\WWW\serverb”

    ServerName serverc
    DocumentRoot “C:\WWW\serverc”

    ServerName serverd
    DocumentRoot “C:\WWW\serverd”

    NOTE the NameVirtualHost 127.0.0.1 line before the VirtualHosts are declared. You need to have this line for everything to work. I hope this helps…

  27. Blog » Blog Archive » more apache setup Says:

    [...] Setting Up Multiple Apache Local Web Sites On Your Computer [...]

  28. Using Local VirtualHosts On Apache 2.0.x - HTNet Says:

    [...] 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 [...]

  29. Tim Says:

    Worked perfectly…really appreciate the help.

  30. J Berg Says:

    Does not seem to work for me (I do use apache 2.2). If I type bugzilla:8001 I get the apache “it works” page. I should get the login page

    Here is my configuration

    Hosts file
    127.0.0.1 localhost
    127.0.0.1 bugzilla

    httpd.conf

    #Listen 0.0.0.0:0
    Listen 8089
    Listen 8001

    # symbolic links and aliases may be used to point to other locations.
    DocumentRoot “D:\Apache2.2\htdocs”

    # This should be changed to whatever you set DocumentRoot to.

    httpd-vhost.conf

    NameVirtualHost *:8089

    # VirtualHost example:

    DocumentRoot “D:\Apache2.2\htdocs”
    ServerName localhost
    ErrorLog logs/defaultsite-error_log
    CustomLog logs/defaultsite-access_log common

    DocumentRoot “D:\BUGZILLA”
    ServerName bugzilla
    ErrorLog logs/bugzilla-error_log
    CustomLog logs/bugzilla-access_log common

    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all

  31. J Berg Says:

    I had to remove the symbols from the lines that dit not show up on this website. Here is my virtual configuration again

    VirtualHost *
    DocumentRoot “D:\Apache2.2\htdocs”
    ServerName localhost
    ErrorLog logs/defaultsite-error_log
    CustomLog logs/defaultsite-access_log common

    VirtualHost *:8001
    DocumentRoot “D:\BUGZILLA”
    ServerName bugzilla
    ErrorLog logs/bugzilla-error_log
    CustomLog logs/bugzilla-access_log common
    VirtualHost

    Directory “D:\BUGZILLA”
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
    Directory

  32. Site Admin Azmeen Says:

    J Berg,

    I think the instructions in Using Local VirtualHosts On Apache 2.0.x would be more suitable for you.

    I use Apache 2.2.x myself and they work like a charm :)

  33. Joe Schwab Says:

    This is a great article.
    does anyone know how i can configure these local host names to be viewable by other machines within the same network. since these are not domains, and there is no internal DNS services, im not sure how this would work.

  34. Site Admin Azmeen Says:

    Hi Joe Schwab,

    It depends on what your web server runs. If it’s on a Linux box, you could run the Samba service and set aliases for the hostnames you want to server pages on.

    On a Windows network, I don’t think there’s a similar function unfortunately. The tedious alternative would be to edit each client’s hosts file.

  35. Joe Schwab Says:

    Hey Azmeen,
    thanks for your response, Im running MAMP on mac OS X (which is essentially unix).

    if i were to edit each clients host file, would i point them to the internal IP address(192.168.1.x)? and not the localhost 127.0.0.1. does that sound about right?

    Joe

  36. Andrew Says:

    I am having the same problem as many others – the first virtualhost becomes the default. I followed all the suggestions in some of the responses (include the NameVirtualHost 127.0.0.1). No luck. What else could this be?

  37. Andrew Says:

    I figured it out. Thank you, bye!

    (Just Kidding)

    The problem I think that many people are having is the syntax. Jeff, you are right. It has to do with the NameVirtualHost directive. I was having trouble because most of the examples are not showing the exact syntax with respects to open and close tags (ie: . So, here is the syntax:

    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all

    NameVirtualHost 127.0.0.1

    ServerName domain1
    DocumentRoot “C:\path_to_domains\domain1\httpdocs”

    ServerName domain2
    DocumentRoot “C:\path_to_domains\domain2\httpdocs”

    Andrew.

  38. Andrew Says:

    …and I see why now! The submission form on this page removes the tags – lol.

  39. Andrew Says:

    so, NameVirtualHost 127.0.0.1 is outside of all tags. By itself.

  40. Taha Yusuf Says:

    Hi all
    i wrote this in my httpd.conf

    Listen 80
    Listen 8000
    Listen 9000

    ServerName example1.domain.com
    Redirect / http://example1.domain.com/page1

    ServerName example2.domain.com
    Redirect / https://example1.domain.com/page2

    but virtual hosts r not working

    when i use port 80 in virtual hosts instead of 8000 and 9000 it works fine

    so what is my problem

    can anyone help ???

    thank you

  41. Taha Yusuf Says:

    LOL tags removed

    VirtualHost *:8000
    ServerName asec2.tarakeeb.com
    Redirect / http://asec2.tarakeeb.com:10038/wps/portal
    /VirtualHost

    VirtualHost *:9000
    ServerName asec3.tarakeeb.com
    Redirect / https://localhost:10003/ibm/console/logon.jsp
    /VirtualHost

  42. Site Admin Azmeen Says:

    Taha Yusuf,

    The example I’m giving below is for Apache 2.2.x (may work for Apache 2.0.x too):

    <VirtualHost asec2.tarakeeb.com:8000>
    ServerName asec2.tarakeeb.com
    Redirect / http://asec2.tarakeeb.com:10038/wps/portal
    </VirtualHost>

    What it does is forward any requests to http://asec2.tarakeeb.com:8000/ to http://asec2.tarakeeb.com:10038/wps/portal.

    Therefore, a request for:
    http://asec2.tarakeeb.com:8000/somedir/somefile.php

    Will be forwarded to:
    http://asec2.tarakeeb.com:10038/wps/portal/somedir/somefile.php

    Please get back to me if you have any further questions.

    Cheers!

  43. Pato Says:

    Hi Danny,

    Thanks man for the very helpful article.

    Please remember to add the following lines to the httpd.conf file for the virtualhost to work.
    # Listen for virtual host requests on all IP addresses
    NameVirtualHost *:80

    Plus when adding the virtual hosts to the conf file indicate the port to listen to as shown below

    Cheers!!!!!!!!

  44. grayf24 Says:

    Options Indexes FollowSymLinks MultiViews

    Why?

  45. deffzp Says:

    Used the coding. And yes you are a legend dude thankyou. I still cannot work out why i cannot use the same ports(for in future if i make more sites. I will have so many different ports for each site)
    thanx Rob

  46. richter_vst Says:

    The submission form on this page removes the tags

  47. mir Says:

    Please remember to add the following lines to the httpd.conf file for the virtualhost to work.

  48. John Aspinall Says:

    I have tried EVERYTHING written in all the above posts and read the guide about three times and still I am getting the same problem as everyone else i.e. only the first web site defined in httpd.conf loads if you are running multiple sites. I’ve addded NameVirtualHost 127.0.0.1 as suggested and set up everything else as suggested and it still refuses to work and always serves up the first web site. Help!

    HOSTS FILE

    127.0.0.1 localhost
    127.0.0.1 local.example1.co.uk
    127.0.0.1 local.example2.co.uk
    127.0.0.1 local.example3.co.uk
    127.0.0.1 local.example4.co.uk

    HTTPD CONF

    Include “c:/wamp/alias/*”

    NameVirtualHost 127.0.0.1

    # ViewTraffic dev site

    DocumentRoot “C:/wamp/www/example2.co.uk/”
    ServerName local.example2.co.uk
    ErrorLog logs/viewtraffic-error_log
    CustomLog logs/viewtraffic-access_log common

    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all

    # My portfolio/blog dev site

    DocumentRoot “C:/wamp/www/example1.co.uk/”
    ServerName local.example1.co.uk
    ErrorLog logs/example1-error_log
    CustomLog logs/example1-access_log common

    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all

  49. erik Says:

    Thanks a ton! this helped.
    Dugg it.

  50. erik Says:

    one side note to the other readers. For me, it was defaulting to the first virtual host defined, like the user from comment #48.

    What I found that worked was changing it to port 80 instead of just “*”

    So in the example above, where he does a directory declaration, instead of “VirtualHost *” put “VirtualHost *:80″

    Also, above all of these, place “NameVirtualHost *:80″ in there.

    this worked for me.

  51. bmw yan Says:

    ou This is fine!!
    I`m Russian
    Sorrу за ошибки если что
    ок?

  52. Robert Says:

    worked like a charm…thanks for clear, concise instructions.

  53. Randy Says:

    I tried several methods and hints shown above but I continue to have the same problem.
    ONLY the first web site defined in httpd.conf loads while I am running multiple sites.

    Can anyone help please?

    my vhost.conf file reads:

    ServerName webzone4
    DocumentRoot Z:\xampp\htdocs

    IndexOptions +FancyIndexing NameWidth=*
    Options Includes FollowSymLinks Indexes
    AllowOverride All
    Order allow,deny
    Allow from all

    ServerName bobbyorr
    DocumentRoot Z:\xampp\htdocs

    IndexOptions +FancyIndexing NameWidth=*
    Options Includes FollowSymLinks Indexes
    AllowOverride All
    Order allow,deny
    Allow from all

    my hosts file reads:

    127.0.0.1 localhost
    127.0.0.1 webzone4.com
    127.0.0.1 bobbyorr.net

  54. manu Says:

    How do i give different ip address to different sites on Linux
    -please help me

  55. Bennny Says:

    please help me i have been reading for hours and i still cant figure this out..

    I just want to host 2 sites onmy xp machine.

    I go to address http://www.site1.com.au and it works! YAY!

    But when i go to http://www.site2.com.au it shows site1???

    This is my vhost.conf file,
    #———————————————-

    ServerName http://www.site1.com.au
    DocumentRoot c:/xampp/htdocs/site1

    AllowOverride
    Options +Indexes FollowSymLinks +ExecCGI
    Order allow,deny
    Allow from all

    #———————————————-

    ServerName http://www.site2.com.au
    DocumentRoot c:/xampp/htdocs/site2

    AllowOverride
    Options +Indexes FollowSymLinks +ExecCGI
    Order allow,deny
    Allow from all

    #————————————————

    and this is my error log,

    [Sun Apr 11 23:59:36 2010] [warn] NameVirtualHost 127.0.0.1:0 has no VirtualHosts
    [Sun Apr 11 23:59:37 2010] [warn] NameVirtualHost 127.0.0.1:0 has no VirtualHosts
    [Sun Apr 11 23:59:38 2010] [notice] Digest: generating secret for digest authentication …
    [Sun Apr 11 23:59:38 2010] [notice] Digest: done
    [Sun Apr 11 23:59:39 2010] [notice] Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1 configured — resuming normal operations
    [Sun Apr 11 23:59:39 2010] [notice] Server built: Nov 11 2009 14:29:03
    [Sun Apr 11 23:59:39 2010] [notice] Parent: Created child process 5964
    [Sun Apr 11 23:59:39 2010] [warn] NameVirtualHost 127.0.0.1:0 has no VirtualHosts
    [Sun Apr 11 23:59:40 2010] [warn] NameVirtualHost 127.0.0.1:0 has no VirtualHosts
    [Sun Apr 11 23:59:41 2010] [notice] Digest: generating secret for digest authentication …
    [Sun Apr 11 23:59:41 2010] [notice] Digest: done
    [Sun Apr 11 23:59:42 2010] [notice] Child 5964: Child process is running
    [Sun Apr 11 23:59:42 2010] [notice] Child 5964: Acquired the start mutex.
    [Sun Apr 11 23:59:42 2010] [notice] Child 5964: Starting 150 worker threads.
    [Sun Apr 11 23:59:42 2010] [notice] Child 5964: Starting thread to listen on port 443.
    [Sun Apr 11 23:59:42 2010] [notice] Child 5964: Starting thread to listen on port 81.
    [Sun Apr 11 23:59:42 2010] [notice] Child 5964: Starting thread to listen on port 80.

    Im just trying to learn! Ive read everything I can and I have modified my config files so many times… i t feels like im going in circles! Thank you so much to anyone that can help. It would be very much appreciated. Thank you!

  56. Tweets that mention Setting Up Multiple Apache Local Web Sites On Your Computer - HTNet -- Topsy.com Says:

    [...] This post was mentioned on Twitter by Ezequiel Lauria. Ezequiel Lauria said: Setting Up Multiple Apache Local Web Sites On Your Computer – HTNet http://shar.es/mGv4f :) [...]

  57. Alabama weddings - Location wedding - Alabama location wedding Says:

    [...] Setting Up Multiple Apache Local Web Sites On Your Computer – HTNet 27 Nov 2006. Both sites work fine. Though if i try to get them to respond when they are. When accessing each site in the address bar all there was, Setting Up Multiple Apache Local Web Sites On Your Computer – HTNet [...]

  58. Jerome Christopher Says:

    Thanks for the detailed information.
    Jerome.

  59. Aaron Says:

    I also had the problem that only the first virtual host’s directory was being used. After further research I found that this apache configuration worked for me (in addition to the windows host file changes):

    Listen 80
    NameVirtualHost *:80

    ServerName site1
    DocumentRoot “G:\site1″

    allow from all
    order allow,deny
    AllowOverride All

    DirectoryIndex index.html index.php

    ServerName site2
    DocumentRoot “G:\site2″

    allow from all
    order allow,deny
    AllowOverride All

    DirectoryIndex index.html index.php

  60. Steve Says:

    Hi there,

    I recently wrote a blog post with a full tutorial on how to set this up properly in a windows environment. Help it helps!

    http://www.kintek.com.au/web-design-blog/configuring-multiple-domains-within-wamp-for-local-development/

    - Steve

  61. Eric Says:

    very useful information. Simply example.

  62. 403 Forbidden HTTP Error on Apache/PHP Site in Linux Home Directory « Wisetek Solutions Says:

    [...] Up Multiple Apache Local Web Sites On Your Computer, http://www.heritage-tech.net/336/setting-up-multiple-apache-local-web-sites-on-your-computer/ Share this:TwitterFacebookLike this:LikeBe the first to like this [...]

  63. <caiguanhao title="Apache:创建多个站点" /> Says:

    [...] 参考:Setting Up Multiple Apache Local Web Sites On Your Computer (1.3.x) and 2.0.x [...]

  64. suksesboy Says:

    My programmer is trying to persuade me to move to .
    net from PHP. I have always disliked the idea because of the costs.
    But he’s tryiong none the less. I’ve been using WordPress on a variety of websites for about a year and am nervous about switching to another platform.
    I have heard good things about blogengine.
    net. Is there a way I can transfer all my wordpress posts into it?
    Any kind of help would be greatly appreciated!