Key Takeaways
- Virtual hosts let you run multiple WordPress sites locally, each with its own custom domain, on a single XAMPP installation.
- Two files need editing:
httpd-vhosts.conffor Apache configuration and the Windows hosts file for domain mapping. - The Windows host file location is
C:\Windows\System32\drivers\etc\hostson Windows 10 and Windows 11. - After configuring the virtual host, you must update the WordPress site URL and home URL in your database via phpMyAdmin.
- Restarting Apache from the XAMPP control panel is required for configuration changes to take effect.
Many developers start web development in their local environment and when the work is done, they migrate their site to a live environment. The local setup provides a flexible development environment for experimenting the new techniques and most importantly managing the project code is a simple matter.
If you are working with WordPress, setting up virtual hosts and XAMPP stack is a straightforward task. XAMPP stack provides you a local platform where you can install and run your WordPress sites right from your Desktop/Mac.
The stack supports the same components as the actual web server and it ensures that when the time comes to take the project live, the database(s) and whole website (s) could be moved easily without any hassle.
In this tutorial, I am going to demonstrate how you can set up and configure virtual hosts for WordPress websites with XAMPP running on Windows 10. I am assuming that you already have XAMPP and WordPress installed on your Windows 10.
If you are interested in setting up a new WordPress site on XAMPP, we have created a detailed guide that goes into the details of installing and running up a WordPress site on XAMPP using our managed WordPress hosting.
What is a Virtual Host?
A virtual host is used for hosting multiple domain names on a single server. This means different websites share the same server and utilities for their desired project.
There are many advantages when you use the virtual host concepts in a live environment and various large-scale companies follow the same principle to provide low-cost web hosting server for their customers. The best example would be shared hosting.
Types of Virtual Hosts
There are three types of virtual hosts; name, IP, and port-based.
In name-based, you can host multiple websites on the same server IP.
In IP-based, each website uses a unique IP address.
In Port-Based, different websites host on a common IP address but distinguish on the basis of the unique port number.
Experience Superior & Hands-Off WordPress Hosting with Autonomous
Cloudways Autonomous offers fully managed WordPress hosting, providing seamless auto-scalability and lightning-fast speed with strong security. No more manual setups and confusing server choices.
How to create a virtual host in XAMPP on Windows 10
In this article, I’m creating a virtual host in a local environment to work around different WordPress projects.
So, let’s get started!
First, you need to navigate to D:\xampp\apache\conf\extra or wherever your XAMPP files are located. In my case, my XAMPP file is located in drive D.

Then, edit httpd-vhosts.conf with any text editor. In my case, I am using Notepad++.

The file looks something like this:

Now, paste the following code at the end of the file text/code:
<VirtualHost *:80> DocumentRoot "D:\xampp\htdocs\testing" ServerName farhan.cw <Directory "D:\xampp\htdocs\testing"> </Directory> </VirtualHost>
In the above code:
- VirtualHost: Most web servers use port 80 as their default port. However, you can change the port to 8080, 8081, etc.
- DocumentRoot: The folder where files of a site will exist. In our case, the folder name is “testing”.
- ServerName: It is the URL for our virtual host.
- Directory: It is the directory of our virtual host.
Now, go to Windows > Search > Run and paste the following line:
C:\Windows\System32\drivers\etc\hosts

Next, open the Host file in your text editor and add the following line in the Host file.
127.0.0.1 farhan.cw

Once you are done, you need to restart Apache and MySQL from the XAMPP control panel and check whether http://localhost/testing opens up in your browser.

You can see that the domain has been changed successfully and a 500 internal server error appears for your previous URL (http://localhost/testing).

Next, we need to change the site URL of our WordPress and therefore, we need to access the database.
Setting up Virtual Hosts for WordPress is easy with Cloudways
Use our managed WordPress hosting for a hassle-free experience
How to configure the WordPress site URL
At this point, I am assuming that you have a WordPress website set up.
Now, it’s time to change the database URL (a very important step to configure virtual host).
For this, open your browser and go to http://localhost/phpmyadmin/ and select your database. In my case, it is “testing”.
Then open wp_options and click edit the site URL from http://localhost/testing/ to http://farhan.cw, and home URL from http://localhost/testing to http://farhan.cw.

Restart Apache and visit your virtual host URL, in our case it’s “farhan.cw” and check whether the domain has been set up successfully.

Since the setup of Virtual Hosts for WordPress Website is done, here is what the final results would look like:

Final Words
Virtual hosts transform a basic XAMPP installation into a proper multi-project development environment. Each WordPress project gets its own domain, its own isolated configuration, and a URL structure that mirrors how the site will behave in production.
The process involves four steps: add a VirtualHost block to httpd-vhosts.conf, map the custom domain in the Windows hosts file at C:\Windows\System32\drivers\etc\hosts, restart Apache, and update the WordPress site URL and home URL in phpMyAdmin.
Once this is set up for one project, adding subsequent projects takes less than five minutes.
If you have any queries or suggestions, feel free to ask me in the comment section below.
Q. What is the Host File Location in Windows 10?
A. The hosts file in Windows 10 is located at C:\Windows\System32\drivers\etc\hosts. You need administrator privileges to edit it. Open your text editor as Administrator before modifying the file, or the changes will not be saved correctly.
Q. What is a Virtual Host in XAMPP?
A. A virtual host in XAMPP lets you assign a custom local domain name to a specific project folder instead of accessing it through localhost. This allows you to run multiple WordPress sites locally, each with its own domain, from a single XAMPP installation.
Q. How Do I Add Multiple Virtual Hosts in XAMPP on Windows 10?
A. Add a separate VirtualHost block in httpd-vhosts.conf for each project, with a unique DocumentRoot path and ServerName for each one. Then add a corresponding line in the Windows hosts file mapping each domain to 127.0.0.1. Restart Apache after making changes.
Q. How Do I Change My Domain Name From Localhost in XAMPP?
A. Edit the hosts file to associate your custom domain with 127.0.0.1, update httpd-vhosts.conf with the matching ServerName and DocumentRoot, restart Apache, and update the siteurl and home values in wp_options via phpMyAdmin to use the new domain.
Q. Why is My Virtual Host Not Working After Setup?
A. The most common causes are a DocumentRoot path mismatch in httpd-vhosts.conf, the hosts file not being saved with administrator privileges, Apache not restarting after configuration changes, or a typo in the ServerName that does not match the hosts file entry.
Q. Where is the Host File Location in Windows 11?
A. The hosts file location in Windows 11 is the same as Windows 10: C:\Windows\System32\drivers\etc\hosts. The editing process and administrator privilege requirement are identical.
Q. Do I Need to Update WordPress Settings After Configuring a Virtual Host?
A. Yes. WordPress stores the site URL in the database. After configuring the virtual host, open phpMyAdmin, select your WordPress database, find the wp_options table, and update both the siteurl and home rows to reflect your new custom domain.
Q. What Are the Three Types of Virtual Hosts?
A. The three types are name-based (multiple sites on the same IP, distinguished by domain name), IP-based (each site uses a unique IP address), and port-based (sites share an IP address but use different port numbers). Name-based is the most common type for local WordPress development with XAMPP.
Owais Khan
Owais works as a Marketing Manager at Cloudways (managed hosting platform) where he focuses on growth, demand generation, and strategic partnerships. With more than a decade of experience in digital marketing and B2B, Owais prefers to build systems that help teams achieve their full potential.