Setup Virtual Host on XAMPP in Windows

Why Virtual Hosts?

Virtual Hosts allows us to define our own domain name during the development process. How cool is it to have something like instead of localhost/myapp? It is always better to setup up virtual host when you are working on multiple applications. It makes the url much more cleaner during the development and also it will give us different cookie and sessions if we are working on multiple apps at the same time. Setting up a virtual host is very easy with just 2-3 steps involved.

How to Setup Virtual Host on XAMPP in Windows

With setting up virtual host you are no longer required to put your source code inside the xampp/htdocs folder. You can put your source code anywhere you want. For this example I am going to setup my app in D:\myapp.

  1. Open C:\xampp\apache\conf\extra\httpd-vhosts.conf
  2. Add the following block of code to make the default localhost working even after adding our virtual host
  3. Add the following block of code after that.
  4. OpenĀ C:\Windows\System32\drivers\etc\hosts in notepad as administrator.
  5. Add the following lines to the file.
  6. Thats All. Now you can open your browser and access your app by entering or

Leave a Reply