Virtual Hosts ?

Nov 11, 2013, by admin

Hi all now we are going to see is what is Virtual Hosts ? hope you all like the post

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:XAMPPhtdocs folder.
Adding a Virtual Host 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:WINDOWSsystem32driversetc.
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:xamppapacheconfextrahttpd-vhosts.conf
At the bottom of that file add
NameVirtualHost *
<VirtualHost *>
DocumentRoot “D:xampphtdocs”
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot “D:Documents and SettingsMeMy DocumentsclientAwebsite”
ServerName webaddress
<Directory “D:Documents and SettingsMeMy DocumentsclientAwebsite”>
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:xampphtdocs 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/