XAMPP virtual hosts in Windows.

If you are developing multiple sites locally, you might have organised your local sites in folders like

“C:\xampp\htdocs\mysite1”, “C:\xampp\htdocs\mysite2”, etc.

Every time you want to visit mysite1 from your browser, you have to write “localhost/mysite1” in the address bar of the browser.

It would be nice to access “mysite1” using a simple host name in place of “localhost/mysite1”.

In this tutorial you will see how to easily setup virtual hosts in xampp.

 

1) We have two folders named “mysite1” and “mysite2” in the htdocs folder.

 

2) Open the “hosts” file located in “C:\Windows\System32\drivers\etc” using notepad.

You must be running notepad with Administrator privilege. To run notepad with Administrator privilege, you can go to Start menu in Windows → All Programs → Accessories. Inside Accessories, right click on Notepad and select Run as administrator.

Now from the notepad window go to File → Open, browse to the “hosts” file in “C:\Windows\System32\drivers\etc”. If you cannot see any “hosts” file there, change the “Text Documents(*.txt)” to “All files(*.*)” as shown in the image below.

windows hosts file

Now you can see the files. Open the “hosts” file.

 

3) Scroll down to the bottom of the “hosts” file, and after line "127.0.0.1 localhost" add the lines shown below.

127.0.0.1 mysite1

127.0.0.1 mysite2

 

(When you visit “mysite1” or “mysite2”, this will tell your browser to look for these sites locally in the computer.)

Save the file.

 

4) In the file "httpd.conf" located in "C:\xampp\apache\conf", search for the line:

Include "conf/extra/httpd-vhosts.conf"

 

If there is a # before the line, delete the # sign and save the file. If the above line does not exist, add the line, and save the file.

 

5) Now, browse to “C:\xampp\apache\conf\extra”, and open the file named “httpd-vhosts.conf” in notepad.

 

6) At the bottom of the file add the following lines. These lines are required to access xampp index, phpmyadmin, etc. by visiting “localhost” from the browser.

 

NameVirtualHost *:80

<VirtualHost *:80>

DocumentRoot "C:\xampp\htdocs"

ServerName localhost

</VirtualHost>

 

 

After the above lines add the following lines. One virtual host for each site.

<VirtualHost *:80>

DocumentRoot "C:/xampp/htdocs/mysite1"

ServerName mysite1

<Directory "C:/xampp/htdocs/mysite1">

Order allow,deny

Allow from all

</Directory>

</VirtualHost>

 

<VirtualHost *:80>

DocumentRoot "C:/xampp/htdocs/mysite2"

ServerName mysite2

<Directory "C:/xampp/htdocs/mysite2">

Order allow,deny

Allow from all

</Directory>

</VirtualHost>

 

Save the file.

 

7) Restart XAMPP and Apache.

Now, you can visit “mysite1” or “mysite2” from the browser and access the sites in respective folders.

 

Related:

Creating Drupal multisite in XAMPP.




You might want to contribute to Qoncious.com:




Latest Videos