Creating Multiple Sites on a Local Web Server

Posted on December 5, 2007 in Tutorial | 8 Comments »

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:
  • NewsVine
  • Technorati
  • Reddit
  • Google
  • StumbleUpon
  • Facebook
  • Digg
  • del.icio.us
  • Ma.gnolia
  • TwitThis

8 Responses

  1. Adrian TurnerDecember 15, 2007 at 8:15 pm

    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?

  2. raghav mathurMarch 24, 2008 at 3:27 pm

    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

  3. Chilli KingMay 15, 2008 at 9:05 am

    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???

  4. TrevorMay 15, 2008 at 9:14 am

    @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.

  5. Chilli KingMay 15, 2008 at 9:29 am

    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?

  6. Chilli KingMay 15, 2008 at 10:20 am

    Hi - just managed to solve the problem thask to this thread:

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

  7. TrevorMay 15, 2008 at 10:23 am

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

  8. 2 sites on XAMPPMay 15, 2008 at 11:33 am

    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. Sick of filling out this form? Register or Log in now.

Who Am I?

Trevor Davis I’m Trevor Davis, a 24 year old Front-End Developer. Basically, I make web sites.

By day, I work for Matrix Group International in Alexandria, VA, and by night, I freelance.

Feel free to get in touch with me about anything.

What Have I Done?

  • Change We Can Believe In
  • Change We Can Believe In
  • Change We Can Believe In
  • Change We Can Believe In
  • Change We Can Believe In
  • Change We Can Believe In
  • Change We Can Believe In
  • Change We Can Believe In

View All My Work »

Bookmarks

  • Google Search Engine Optimization Starter Guide [PDF]

    Google has released a free 22-page Search Engine Optimization Starter Guide containing plenty of well-written, practical and straightforward advice for webmasters. If you've been looking into SEO for a while it probably won't contain anything new for you, but it's useful as a set of guidelines as to what Google considers to be good optimization practice. (psst, Google, with just a little design work it could have looked so much nicer!)

  • The importance of setting expectations

    To make your customer's experience better, be sure to set their expectations.

  • XML Sitemaps Generator

    Insert your URL and let it generate the XML sitemap for you. Very useful for static websites.

  • Train-ee ExpressionEngine Training

    Learn ExpressionEngine with books, screencasts, classroom training and free tutorials from Train-ee.com

  • web.without.words

    Weekly gallery of popular websites reconstructed by removing all words and images, replacing them with blocks.

View All My Bookmarks »