How to Configure Virtual Host on Windows 10

What is a Virtual Host?

A virtual host is used for hosting multiple domain names on a single server. Web developers mostly use virtual hosts to create multiple alias names for the localhost. We can set up any number of virtual hosts to access them with a specific name.
Generally, web developers develop multiple sites using

http://localhost/site_1/
http://localhost/site_2/

URLs but with the help of virtual hosts, we can assign different alias to each of these websites. Like

http://mysite_1.dev
http://mysite_2.dev

Steps for creating Virtual Host:

  1. Create a project directory in the root directory of your web server.
    My Project Path: D:\xampp\htdocs\srashty

  2. Navigate to the D:\xampp\apache\conf\extra directory or wherever your XAMPP files are located.

  3. Open httpd-vhosts.conf file in edit mode with any text editor like Notepad++

  4. Paste the below code to the end of the file mentioned in step 2.
    DocumentRoot “D:\xampp\htdocs\srashty” ServerName srashty.dev

    Note:
    Many web servers use port 80 but you can change the port above as per your web server.
    srashty.dev is the URL of the virtual host which you want to create.

  5. Navigate to the directory C:\Windows\System32\drivers\etc\

  6. Open hosts file with a text editor

  7. Add the below line to the end of the file
    127.0.0.1    srashty.dev

  8. Restart Apache/MySQL via XAMPP control panel.

  9. Open the web browser and browse the url http://srashty.dev

  10. You can start to work on your project inside D:\xampp\htdocs\srashty directory

Leave a Reply

Your email address will not be published. Required fields are marked *