Setting up Virtual Hosts with XAMPP running on Windows XP

2008 Jul 30
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       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 <>\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

      DocumentRoot E:/xampp/htdocs/    # change this line with your htdocs folder
      ServerName localhost


  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:

  DocumentRoot "E:\www\tildemark.com"
  ServerName tildemark.com
  ServerAlias tildemark.com

  CustomLog "E:\www\tildemark.com\tildemark.com-access_log" combined
  ErrorLog "E:\www\tildemark.com\tildemark.com-error_log"

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




Tweet this post

Related Entries

14 Comments

Nice tutorial, but I have a question... So what if you're using subdomains?

Like this? for abc.tildemark.com


DocumentRoot "E:\www\tildemark.com\abc"
ServerName abc.tildemark.com
ServerAlias abc.tildemark.com

CustomLog "E:\www\abc.tildemark.com\tildemark.com-access_log" combined
ErrorLog "E:\www\abc.tildemark.com\tildemark.com-error_log"


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

lemme know...

Thanks
zero

It will be similar to this:

DocumentRoot "E:\www\tildemark.com\abc"
ServerName abc.tildemark.com
ServerAlias abc.tildemark.com

CustomLog "E:\www\tildemark.com\abc\tildemark.com-access_log" combined
ErrorLog "E:\www\tildemark.com\abc\tildemark.com-error_log"

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

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

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

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

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 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 www.mxyzplk.com
ServerAlias 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.

Great tutorial! It worked perfectly!

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
DocumentRoot C:/xampp/htdocs
ServerName localhost

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

ServerAdmin webmaster
DocumentRoot C:/xampp/htdocs/mycharity/dev/
ServerName mycharity.dev

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

ServerAdmin webmaster
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

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.

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

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

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

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

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

Leave a comment


About Me


Alfredo Sanchez is an internet professional focusing on the study search engines behavior in particular. Supports Free Open Source Software and currently develops applications with it using XAMPP.

Recent Entries

Close