creating Virtual Host in xampp or wamp

Leave a Comment
Before we create virtual host,first understand what is virtual host and why do you need it?.

Virutal Host:
Virtual Host means run more than one web site (such as company1.example.com and company2.example.com) on a single machine.

Suppose you have few website running on your local server namely web1,web2 and web3. You access this website from your browser by following url's  http://localhost/web1,http://localhost/web2,http://localhost/web3. But this creates problem when you have same cookie or session on different website because cookie or session will be created for our case domain 'localhost'.

If you create virtual host like local.web1.com ,local.web2.com, local.web3.com then cookie or session will be different for different domain.

Now we will create virtual host on your machine.

Step 1. update httpd.conf.

NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.local.web1.com 

DocumentRoot /xampp/htdocs/web1
</VirtualHost>

<VirtualHost *:80>
ServerName www.local.web2.com 
DocumentRoot /xampp/htdocs/web1

</VirtualHost>



<VirtualHost *:80>
ServerName www.local.web3.com 

DocumentRoot /xampp/htdocs/web1
</VirtualHost>



Step 2. change hosts file which you can find here 'C:\Windows\System32\Drivers\etc '. You must open hosts file with administration privilege.

add following lines

127.0.0.1      www.local.web1.com
127.0.0.1      www.local.web1.com 
127.0.0.1   www.local.web1.com 

now we have done with the creating virtual host. After this you can locate your website from browser using any of these three link.


you can choose any name for your virtual host and you can create as many as you want.

 

0 comments:

Post a Comment