Setting up Virtual Hosts with XAMPP running on Windows XP

virtual.gifSetting up virtual hosts with XAMPP is very straight forward and could be done in less than 5 minutes. Although, your local XAMPP server will still work even if virtual hosts are not configured. You might want to ask, is there a need for my local XAMPP setup to configure virtual hosts? Apparently, virtual hosts are needed when

  • your on multiple domains
  • your need to test your projects with same configuration with the server
  • test your projects without touching your public server
  • your just organizing your projects into groups
  • or setup a local copy of your blog or website

What do we need?
This document assumes that you are working with Windows XP with XAMPP. If you don’t have XAMPP, get it at their XAMPP for Windows download page. Just execute the exe file and follow the onscreen instructions.

Configuring Windows XP to accept hosts
Hosts is a file under Windows XP that is used to map IP addresses to a custom list of hosts or maybe domain names. The IP address should be placed in one line. The first column should contain the IP address and on the second column its corresponding hostname. The IP address may be separated by a space or by a tab. You can place comments by prepending your line this symbol ‘#’ (pound sign). Initially the first line is added. Now lets add our domain tildemark.com

127.0.0.1       localhost
127.0.0.1       www.tildemark.com
127.0.0.1       tildemark.com

you can check your work by doing a ping to your configured host.
pinging-tildemark.com.jpg

Configuring XAMPP to accecpt Virtual Hosts

  1. Got to your Apache folder in XAMPP and locate the conf files. The are usually located at <<local path>>\xampp\apache\conf\extra
  2. Open the file named httpd-vhosts.conf with a text editor
  3. If posible read the instructions so may have the idea on what you are doing
  4. Now paste the following code at the bottom of the file without touching the document.
    NameVirtualHost 127.0.0.1:80
    <VirtualHost 127.0.0.1:80>
    DocumentRoot E:/xampp/htdocs/    # change this line with your htdocs folder
    ServerName localhost
    </VirtualHost>
  5. Edit the line DocumentRoot with your own document root folder
  6. For each domain you are to configure paste the following lines below, just replace my domain name your corresponding domain:

<VirtualHost www.tildemark.com>
DocumentRoot "E:\www\www.tildemark.com"
ServerName www.tildemark.com
ServerAlias www.tildemark.com
CustomLog "E:\www\www.tildemark.com\www.tildemark.com-access_log" combined
ErrorLog "E:\www\www.tildemark.com\www.tildemark.com-error_log"
<Directory "E:\www\www.tildemark.com">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Comments

19 Comments on "Setting up Virtual Hosts with XAMPP running on Windows XP"

  1. zero says:

    Nice tutorial, but I have a question… So what if you’re using subdomains?
    Like this? for abc.tildemark.com
    DocumentRoot “E:\www\www.tildemark.com\abc”
    ServerName abc.tildemark.com
    ServerAlias abc.tildemark.com
    CustomLog “E:\www\abc.tildemark.com\www.tildemark.com-access_log” combined
    ErrorLog “E:\www\abc.tildemark.com\www.tildemark.com-error_log”
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    lemme know…
    Thanks
    zero

  2. tildemark says:

    It will be similar to this:
    DocumentRoot “E:\www\www.tildemark.com\abc”
    ServerName abc.tildemark.com
    ServerAlias abc.tildemark.com
    CustomLog “E:\www\www.tildemark.com\abc\www.tildemark.com-access_log” combined
    ErrorLog “E:\www\www.tildemark.com\abc\www.tildemark.com-error_log”
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all

  3. Current config:
    Configuration about the current demo OS
    VMware Workstation 5.5.3 build-43685, Windows XP SP3 installed.
    with Internet Explorer 7
    written by: fred-eric [at] lafaille [dot] ca
    on: March 2 2009
    video 2: customizing xampp to use it with virtual folder.
    ————————————————————
    before customizing xampp make sure you stop apache service
    1- create virtualhost folder in web folder
    c:\web\virtualhost
    2- create domain for virtual folder, here test.
    c:\web\virtualfolder\ilovephp
    3- Edit c:\windows\system32\drivers\etc\hosts add this line:
    127.0.0.1 ilovephp
    4- Save and close
    5- open c:\web\xampp\apache\conf\extra\httpd-vhosts.conf (\apache\conf\extra\httpd-vhosts.conf)
    6- uncomment line 19
    #
    # Use name-based virtual hosting.
    #
    NameVirtualHost *:80
    7- Add default htdocs folder for localhost
    N.B: By doing this you lose access to your default htdocs directory.
    To fix this, you have to create an extra vhost with ServerName localhost
    which points to your htdocs directory.
    ServerAdmin admin@localhost.com
    DocumentRoot C:/web/xampp/htdocs
    ServerName localhost
    ServerAlias localhost
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
    8- Add new test domain virtualhost
    ServerAdmin admin@localhost.com
    DocumentRoot C:/web/virtualfolder/ilovephp
    ServerName ilovephp
    ServerAlias ilovephp
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
    9- start Apache with xampp control
    10- open the test domain with browser
    http://ilovephp
    That’s it your done…..
    Support my videos, Payed me a cup of coffee!
    If you have enjoy viewing this video and would like to help,
    we would greatly appreciate your voluntary support payment.
    http://www.lafaille.ca/donate.php

  4. ajay says:

    hi Alfredo Sanchez
    I uses your artical and configuration for domain, when i change to httpd-vhosts.conf to way you said not my Xampp is not running Busy port 80
    any clue
    I am new i would be greatful if you can help me to setup my own server, i have domain registed

  5. ajay says:

    hi Alfredo Sanchez
    I uses your artical and configuration for domain, when i change to httpd-vhosts.conf to way you said not my Xampp is not running Busy port 80
    any clue
    I am new i would be greatful if you can help me to setup my own server, i have domain registed

  6. mxyzplk says:

    Hi Alfredo,
    I have some weird problem..
    I already set the host like this
    127.0.0.1 localhost
    127.0.0.1 mxyzplk.com
    127.0.0.1 http://www.mxyzplk.com
    NameVirtualHost *
    DocumentRoot “D:\xampp\htdocs”
    ServerName localhost
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
    DocumentRoot “D:\xampp\htdocs\magento”
    ServerName http://www.mxyzplk.com
    ServerAlias http://www.mxyzplk.com
    Order allow,deny
    Allow from all
    the problem is when I try to access my site on localhost, it goes to xampp…
    its automatically goes to http://www.mxyzplk.com/xampp not to the path that I point…
    I hope you can help..
    regards.

  7. Liz says:

    Great tutorial! It worked perfectly!

  8. Paul says:

    Hey, Cheers for this post. It is helpful, however similar prob to Alfredo. I had this all working before with xampp, I have http://localhost with two virtual hosts http://myclub.dev and http://mycharity.dev. It seems to be broken now with the config below, all query urls (localhost, mycharity and myclub) go to ‘C:/xampp/htdocs/mycharity/dev/’ directory, which is the mycharity.dev vhost dir. If I rename all virtual hosts to *:80 advised in your post instead of the below, all are redirected to ‘C:/xampp/htdocs’ being localhost directory. *:80 used to work when I had this working.
    NameVirtualHost *:80
    ServerAdmin webmaster@localhost
    DocumentRoot C:/xampp/htdocs
    ServerName localhost
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
    ServerAdmin webmaster@localhost
    DocumentRoot C:/xampp/htdocs/mycharity/dev/
    ServerName mycharity.dev
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
    ServerAdmin webmaster@localhost
    DocumentRoot C:/xampp/htdocs/myClub/dev/web_root/
    ServerName myclub.dev
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
    My hosts file is also valid at ‘C:\Windows\System32\Drivers\etc\hosts’.
    127.0.0.1 localhost
    127.0.0.1 mycharity.dev
    127.0.0.1 myclub.dev
    Any help is greatly appreciated.
    /Paul

  9. PaulC says:

    If when you set this up, you find that you are constantly redirected to http://yurdomain/xampp then you probably have 1 of two problems happening, maybe both:
    1) Verify that you have stopped and restarted the Apache server. In later versions of xampp, Apache is running as a service. Make sure that it is *really* stopped and restarted.
    2) *Clear the browser cache*. Don’t just stop and restart the browser! I can’t say this often enough or loud enough. This had us waisting the best part of a day, due to Firefox caching a previous url fetch.

  10. How about setting up virtual host on windows 7? It failed when I try to add host at the hosts file.
    My hosts configuration :
    127.0.0.1 localhost dipasar
    The result when I tried to ping is :
    Pinging 127.8.0.149 [127.8.0.149] with 32 bytes of data:
    Request timed out.
    Request timed out.
    Request timed out.
    Reply from 127.0.0.1: bytes=32 time=4ms TTL=128

  11. tildemark says:

    I am not familiar with Win7 hosts but i can see that there is something odd with your ping, it says 127.8.0.149, if you are pinging to localhost, it should come up as pinging 127.0.0.1

  12. Thanks for your tutorial… now I´m trying to make it work… but I´ll find a way.

  13. simion.chis says:

    Thanks for this fantastic tutorial.
    Went from first attempt on Windows 7.

  14. simion.chis says:

    Thanks for this fantastic tutorial.
    Went from first attempt on Windows 7.

  15. John Porter says:

    Great tutorial, never got this to work before today, you’ve explained a difficult process very well I think!
    Question: How can I get my colleagues on the same network to access the virtual sites on my computer? I know it has to do with the ‘hosts’ file on their computers somehow…

  16. tildemark says:

    Hello John,
    Just edit the host file on your friends PC with your servers IP address like this
    192.168.1.2 http://www.johnporter.com
    where:
    192.168.1.2 is you ip address and
    http://www.johnporter.com is the name you wanted your friends to type into their browsers.

  17. Michael says:

    In later versions of xampp, Apache is running as a service. Make sure that it is *really* stopped and restarted.

  18. Tom Haws says:

    Thank you. This worked for me after http://www.richardcastera.com/2010/04/04/how-to-setup-a-local-web-server-on-your-computer-using-xampp/ did not quite work.
    Richard’s left me with the sub-url still looking at the htdocs directory. Now everything is better. Thanks.
    By the way, in my Windows 7, running Apache as a service appears to be optional via a little checkbox in the XAMPP control panel that I left unchecked.

  19. dobby says:

    I am using xampp to debug magento, and it works, Thank you!


Here's your chance to leave a comment!