How to Set Up Virtual Hosts in Windows

Set up XAMPP server for Windows. See https://www.apachefriends.org/download.html

Start your XAMPP server by clicking on xampp-control.exe

Click Start Apache and Start mysql.

How to set up Virtual Hosts in Windows.

Add your site files to htdocs folder. 

Eg. For example, add wordpress files to the folder wordpress521 in xampp/htdocs/

C:/xampp/htdocs/wordpress521/

Eg. For example, add phpinfo.php to the folder demo in xampp/htdocs/

C:/xampp/htdocs/demo/phpinfo.php

This file is located at C:\XAMPP\apache\conf\extra\httpd-vhosts. conf . With your editor, open the configuration file and at the end of the document add the code snippet below. Apache configuration files use directives to set rules that should be followed by the server.

<VirtualHost *:80>
                DocumentRoot "C:/xampp/htdocs/wordpress521"
                ServerName wordpress521
</VirtualHost>
<VirtualHost *:80>
                DocumentRoot "C:/xampp/htdocs/demo"
                ServerName demo
</VirtualHost>

Be sure to Stop Apache and Stop Sql and restart Apache and Sql. This will reload the http-vhosts.conf file.
 
Now you can access your websites on your XAMPP server like this:

wordpress521

Or

demo/phpinfo.php
 

2. Set up hosts file in Windows


The file is located here: C:\Windows\System32\drivers\etc\hosts

Open Notepad in Windows

Click Run as administrator

Open the file here:  C:\Windows\System32\drivers\etc\hosts

Add these lines:

127.0.0.1              wordpress521
127.0.0.1              demo

Click Save As and make sure the All Files is selected for Save As Type: