Sorry @averyvery, I won the February blog award.

Creating Multiple Sites on a Local Web Server

So while I was redesigning my site, I needed somewhere to develop the new design. I didn’t want to have to setup a sub-domain on the live site because that would be a pain to have to FTP files up everytime I changed something. So I installed XAMPP on my computer.

Basically, XAMPP is a all in one Apache web server. It installs Apache, PHP, MySQL…everything I needed.

Once you install it, you get a web directory here C:\Program Files\xampp\htdocs (or whichever directory you install XAMPP to). That’s great, everything works fine when you put things in that directory and browse to localhost. But what about if you want to setup multiple sites? That is where I really had to do some digging.

Setting Up Multiple Sites

I found this really good article that walks you through setting up multiple sites on XAMPP. The article was a little longer than I thought it had to be, so I thought I would clarify some things.

  1. Find this file: C:\Program Files\xampp\apache\conf\extra\httpd-vhosts.conf, and open it in notepad.
  2. Find a line that says something like NameVirtualHost *:80. Remove the # sign that you see in front of it; this turns it from being a comment to code that is actually executed. (This was not in any instructions I could find)
  3. Next, scroll to the bottom, and you can add multiple domains. Here is what mine looks like:

    <VirtualHost *:80>
    ServerAdmin webmaster@localhost.trevordavis.dev
    DocumentRoot "C:/sites/trevordavis.dev/webpages"
    ServerName localhost.trevordavis.dev
    </VirtualHost>
    
    <VirtualHost *:80>
    ServerAdmin webmaster@localhost.trevordavis.redesign
    DocumentRoot "C:/sites/trevordavis.redesign/webpages"
    ServerName localhost.trevordavis.redesign
    </VirtualHost>
  4. Finally, find this file: C:\WINDOWS\system32\drivers\etc\hosts and open it in notepad. You need to add an entry for each site you setup in the httpd-vhosts.conf file. My file looks like this:

    127.0.0.1 localhost
    127.0.0.1 localhost.trevordavis.dev
    127.0.0.1 localhost.trevordavis.redesign

That’s It

Once you have done this you can browse to http://localhost.trevordavis.dev and http://localhost.trevordavis.redesign on your computer when you have your web server running. This means that you can view PHP files and execute SQL locally.

It’s great.

Let me know if you have any questions.

Share This:
  • del.icio.us
  • Digg
  • Twitter
  • Facebook
  • StumbleUpon
  • Google Bookmarks
  • NewsVine
  • Technorati
  • Reddit
  • LinkedIn

RSS feed of comments for this entry

    • Adrian Turner
    • 12.15.2007 at 8:15 pm
    • #
    • Reply »

    When i enter:

    http://localhost.seeyouin1984.dev/

    my site doesn’t load i just get another version of the page that lets you know the install was successful and the url changes to:

    http://localhost.seeyouin1984.dev/xampp/

    I there something I could have missed?

    • raghav mathur
    • 3.24.2008 at 3:27 pm
    • #
    • Reply »

    NameVirtualHost 127.0.0.1

    DocumentRoot “c:/site1″
    ServerName http://www.yoursite.com

    Order Deny,Allow
    Allow from all

    u missed the directory part to set permission jus add u will be oaky

  1. Trev, nice site, nice explanation but for the life of me i can’t get it to work!!!

    I’ve got this in my hosts file:

    127.0.0.1 localhost
    127.0.0.1 localhost.chilliking
    127.0.0.1 localhost.cycling

    and this in my vhosts.conf file:

    DocumentRoot “E:\xampp\htdocs\cycling”
    ServerName localhost.cycling

    DocumentRoot “E:\xampp\htdocs\chilliking”
    ServerName localhost.chilliking

    When I browse to http://localhost.cycling/ or http://localhost.thechilliking/ i get the following error:

    Could Not Connect to Server
    Webwasher was not able to connect to localhost.cycling.
    If you would like to try again, click here.

    Interestingly when i try to browse to http://localhost/ i can view the cycling site no problems. The only way i can successfully view the chilli site is o switch the order of the entries in the vhosts file. i .e. change the text above to :

    DocumentRoot “E:\xampp\htdocs\chilliking”
    ServerName localhost.chilliking

    DocumentRoot “E:\xampp\htdocs\cycling”
    ServerName localhost.cycling

    Any ideas???

  2. @Chilli King-
    Did you find this line NameVirtualHost *:80? By default, it should be commented out (# at the beginning of the line). Make sure you un-comment that line.

  3. thanks for the reply. i’ve uncommented that line so now i have:

    NameVirtualHost *:80
    VirtualHost *:80
    DocumentRoot “E:\xampp\htdocs\chilliking”
    ServerName localhost.chilliking
    /VirtualHost

    VirtualHost *:80
    DocumentRoot “E:\xampp\htdocs\cycling”
    ServerName localhost.cycling
    /VirtualHost

    unfortunately i still get the same behaviour….nothing unless i just browse to http://localhost, where i can then view whichever site comes first in my vhosts file.

    Any other ideas?

  4. Hi – just managed to solve the problem thask to this thread:

    http://forums.whirlpool.net.au/forum-replies-archive.cfm/569991.html

  5. @Chilli King-
    Great! What was the issue you were having and how did you solve it?

  6. not sure exactly what my problem was howevr here is exactly what i did:

    If you are having a problem setting up multiple web sites using XAMPP try the following process:

    Assumptions- root folders for your two sites are:

    c:/mysite/
    c:/myweb/

    1) add these lines to the Windows Hosts file

    127.0.0.1. myweb
    127.0.0.1. mysite

    2) Into Apache’s “\xampp\apache\conf\Http.conf” file add the following:


    <Directory c:\myweb>
    Order allow,deny
    Allow from all
    </Directory>

    <Directory c:\mysite>
    Order allow,deny
    Allow from all
    </Directory>

    3) Add this is the “\xampp\apache\conf\extra\httpd-vhosts.conf” file:


    <VirtualHost *:80>
    ServerName myweb
    DocumentRoot C:\myweb
    <Directory C:\myweb>
    IndexOptions +FancyIndexing NameWidth=*
    Options Includes FollowSymLinks Indexes
    AllowOverride All
    Order allow,deny
    Allow from all
    </Directory>
    </VirtualHost>

    <VirtualHost *:80>
    ServerName mysite
    DocumentRoot C:\mysite
    <Directory C:\mysite>
    IndexOptions +FancyIndexing NameWidth=*
    Options Includes FollowSymLinks Indexes
    AllowOverride All
    Order allow,deny
    Allow from all
    </Directory>
    </VirtualHost>

    Now open a browser and simple type either myweb or mysite and you should be able to see both of your site wih all the php in their full glory!

Speak Your Mind

* Denotes Required Field

  1. To post code snippets, use <pre><code>YOUR CODE HERE</code></pre>
Me, Trevor Davis. My blue steel face…

Hi, I’m Trevor Davis

I’m a 25 year old Front-End Developer living in Arlington, VA. I work full-time at Viget Labs and freelance on the side.

I specialize in CSS, HTML, jQuery, WordPress & ExpressionEngine. See more of my work, and then hire me.

Recent Work

  • 4th District IBEW Health Fund
  • Employers Council on Flexible Compensation
  • Monica Davis
  • The National Christmas Tree
  • Matrix Group International
  • The MatriX Files
  • Wireless Career
  • George Washington Wired
  • Direct Selling 411
  • Makeup Bizz
  • InstallNET
  • National Park Foundation
See More of My Work

Asides