Create Virtual host on Windows
With name it might appear a hectic task to setup virtual host on your machine but believe me its just 2 mins job with just three steps .
Setting up a virtual host allows you to use an duplicate or alias name for your localhost. We can setup multiple virtual host as per our need so that each local website can be accessible through specific name. it will save your struggle to setup projects on your local machine.
Lets Start :
Follow below mentioned steps :
Open httpd.conf file which can be found in C:\xampp\apache\conf\httpd.conf And find this line by pressing ctrl+f
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
And replace it with
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
So basically # sign represnt the comment in this file . so we have uncommented it , now lets go to second step
Now Open httpd-vhosts.conf file which can be found in C:\xampp\apache\conf\extra\httpd-vhosts.conf
and copy the below line
<VirtualHost *:80>
ServerAdmin webmaster@localhost.com
DocumentRoot <path to your localhost root >
ServerName <server name that you want to keep like localserverdev.com>
</VirtualHost>
So basically in above code we had to change just 3rd and 4th line where 3rd line we provide our root directory of project . so lets suppose my project name is flipkart and i have setup it in C:\xampp\htdocs\flipkart so we will provide C:\xampp\htdocs\flipkart in 3rd line
and 4th line ask for server name or you can also say domain name .this is the name through which your project will be accessed in browser so lets suppose it named it as facebook.local.com. so my project can be accessed in browser by typing http://facebook.local.com
Now last step
Open C:\Windows\System32\drivers\etc\hosts file
Now make sure you open this file as administrator so that you can edit it
Now find this line 127.0.0.1 and replace this complete line with below
127.0.0.1 facebook.local.com
Now restart your XAMPP/WAMPP server and acess the domain(server name ) in browser in my case i will acess it like
http://facebook.local.com
To create multiple virtual host simply add this line multiple time according to your project directory and domain name(in may case i name second domain as twitter.local.com)
<VirtualHost *:80>
ServerAdmin webmaster@localhost.com
DocumentRoot <path to your localhost root >
ServerName facebook.local.com
</VirtualHost>
Go to C:\Windows\System32\drivers\etc
and open hosts file. Hosts file will look something like below.
127.0.0.1 facebook.local.com
127.0.0.1 twitter.local.com
NOTE : Make sure that you are using localhost on default port 80 otherwise change your port to 80 before setting up the virtual host.
Thats it .
Now Keep learning and spreading whatever little thing you know.
Cheers
A.