Setting up Virtual Hosts with XAMPP running on Windows 7 & Windows XP

Virtual Hosts simply give you the ability to “host” more than one Website and domain on your computer.

 

With a virtual host you can have separate local domain names for each of your Websites.for example, http://website1/ for one site and http://website2/ for another etc. When you type the URL for the Virtual Host in your Web browser, the browser doesn’t go out onto the internet to find the site, but instead asks for the proper file from the Webserver running on your computer. Virtual Host not only let you run multiple Web sites on your computer, but it also let you store the files for those sites anywhere on your computer and not just in the D:\XAMPP\htdocs folder.

 

Adding virtual hosts with xampp in windows system is 2-step process.

 

1. Add a new entry to your computer’s hosts file.
Open the hosts file located at D:\WINDOWS\system32\drivers\etc.

At the end of that file, you will get
127.0.0.1  localhost
127.0.0.1 is how a computer refers to itself—it’s an IP address of computer. The second part “localhost” is the “domain” of the virtual host.

Add new line like
192.168.0.06  webaddress

Save and close the hosts file.

 

2. In Notepad open the Apache configuration file located at D:\xampp\apache\conf\extra\httpd-vhosts.conf

At the bottom of that file add


NameVirtualHost *
<VirtualHost *>
DocumentRoot "D:\xampp\htdocs"
ServerName localhost
</VirtualHost>


<VirtualHost *>
DocumentRoot "D:\Documents and Settings\Me\My Documents\clientA\website"
ServerName webaddress
<Directory "D:\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 D:\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 can add more virtual host according to your need.
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, the virtual host name.
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 or from Windows Control Panel => Administrative Tools => Services.

Open web browser and type a URL for the virtual host. For example: http://webaddress/
and you will get homepage of your website.

 

For more information you can go the below link.
http://httpd.apache.org/docs/2.2/vhosts/

 

Leave a Reply

Your email address will not be published. Required fields are marked *