Setting Up Virtual Hosts for XAMPP

Virtual Hosts give you the ability to “host” more than one Web site and domain on your computer. With a virtual host you can have separate local domain names for each of your Web sites: for example, http://clientA/ for one site and http://clientB/ for another.

Adding a Virtual Host is a 2-step process:

  • Launch Notepad and open the hosts file located at

C:\windows\system32\drivers\etc\hosts. (You may not be able to see the windows folder–some files are hidden by default under Windows)

  • At the end of that file type:
    127.0.0.1      clientA.in

127.0.0.1 is how a computer refers to itself—it’s an IP address that points back to the computer, kind of like a computer’s way of saying “ME.” The second part (clientA.in) is the “domain” of the virtual host. To visit this domain in a Web browser you’d type http://clientA.in. You don’t have to add the .in part to the hosts files—you could just as easily add 127.0.0.1 clientA and access the site in your Web browser with http://clientA—but I find it helpful for differentiating between a real Web site out on the Internet like clientA.com, and the test sites I have running on my own computer.

In Notepad open the Apache configuration file located

  • at C:\xampp\apache\conf\extra\httpd-vhosts.conf
  • At the bottom of that file add:

NameVirtualHost *
<VirtualHost *>
DocumentRoot “C:\xampp\htdocs”
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot “C:\Documents and Settings\Me\My Documents\clientA\website”
ServerName clientA.in
<Directory “C:\Documents and Settings\Me\My Documents\clientA\website”>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

The first five lines of code turn on the Virtual Host feature on Apache, and set up the C:\xampp\htdocs folder as the default location for http://localhost. That’s important since you need to be able to access the XAMPP web pages at http://localhost/ so that you can use PHPMyAdmin.

You’ll need to modify the stuff highlighted in blue color. The first item — DocumentRoot — indicates where the files for this site are located on your computer.

The second part–ServerName — is the name you provided in step 2 above: the virtual host name.

For example, clientA.in.

The third item — the <Directory> part — is the same path you provided for the DocumentRoot.

This is required to let your Web browser have clearance to access these files.

  • Save and close the Apache configuration file, and restart Apache from the XAMPP control panel.
  • Start a Web browser and type a URL for the virtual host. For example: http://clientA.local/.You should now see the home page for your site.

Leave a Reply