Create virtual hosts in Windows XAMPP

Wonder how you can create virtual hosts and access your sites in more fancy way or want to multidomain websites? Well,its pretty easy, follow below steps to achieve it.
Prerequisites:
  1. To do this you must have installed XAMPP or WAMP, whichever you prefer. I have XAMPP so the steps would be more related to XAMPP. But you can follow these for WAMP as well.
  2. You also must need to have admin rights to your computer.
 
Now follow below steps,
  1. Open Notepad by right clicking on it and select "Run as Administrator"
  2. Then click "File" -> on open file fron URL "C:\Windows\System32\drivers\etc" named "hosts". (Note: If you cant see any file then select "All Files" in the bottom)
  3. Once you have opened it put "127.0.0.1       localhost" in one line and just below your domain name like "127.0.0.1       umesh.localhost.com" and save it.
  4. Then go to your XAMPP/WAMP directory and find "httpd-vhosts.conf" file. It must be inside Apache directory. In my case its in "C:\xampp\apache\conf\extra" and open it.
  5. Then copy the code insde it which is commented and paste below. The code looks something like,
    ##<VirtualHost *:80> 
        ##ServerAdmin webmaster@dummy-host2.example.com
        ##DocumentRoot "C:/xampp/htdocs/dummy-host2.example.com"
        ##ServerName dummy-host2.example.com
        ##ErrorLog "logs/dummy-host2.example.com-error.log"
        ##CustomLog "logs/dummy-host2.example.com-access.log" common
    ##</VirtualHost>
  6. Remove commnets and make changes as per your needs. So in my case those would be like,
    <VirtualHost *:80>
        ServerAdmin webmaster@umesh.localhost.com
        DocumentRoot "C:/xampp/htdocs/umesh-files"
        ServerName umesh.localhost.com
        ErrorLog "logs/umesh.localhost.com-error.log"
        CustomLog "logs/umesh.localhost.com-access.log" common
    </VirtualHost>
  7. Then go to XAMPP/WAMP control panel and restart the Apache.
  8. Now paste your newly created domain in browser (in my case it is "umesh.localhost.com") address bar and you are good to go.

Hope this has helped you, if you are facing any issies starting Apache then go to XAMPP's root directory and run batch file named "apache_start.bat" and it will show if there are any errors.

If you still have trouble with this please write me in comment section below.

Thanks!!

 

 
 
 
Author: 

Add new comment