How to a Configure Virtual Host on Windows 10

by Saud Razzak  May 24, 2017

Many developers start development at their local environment and then go to testing/staging environment when the work is done. In many instances, the local environment has minimal resources required for development. Most of the developers like to develop a website in a localized environment.  If you are working with WordPress, setting up virtual hosts and free XAMPP/WAMP stack is a straightforward task.

XAMPP/WAMP stack ensures that when the time comes to take the project live, the database(s) could be moved easily without any hassle.

In this tutorial, I am going to demonstrate how you can set up virtual hosts for WordPress websites with XAMPP running on Windows 10.

Configure Virtual Host on Windows 10

Create the Virtual Host

First, you need to navigate to C:/xampp/apache/conf/extra or wherever your XAMPP files are located.

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

httpd-vhosts file

The file looks something like this:

File look

Delete everything in the file and paste the following code:

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 “WordPress”.
  • 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:

Run

Next, open Host file in your text editor.

Host File

Add the following line in the Host file.

Edit Code in Host File

Once you are done, check whether wordpress.localhost opens up in your browser.

Virtual Host Result

You can see that the domain has been added successfully. You are now free to run the application of your choice in the virtual host. In my case, I will opt for WordPress.

Setting Up WordPress on Virtual Host

At this point, I am assuming that you have already installed XAMPP server and have a WordPress website set up.

WordPress Database Changes

Now, it’s time to change the database URL (a very important step in the configuration of a virtual host).

For this, go to http://localhost/phpmyadmin/ and select your database. In my case, it is “WordPress”.

Select Database

Then go to WordPress > wp_options and change the siteurl from http://localhost/WordPress/ to http://WordPress.localhost, and home URL from http://localhost/WordPress/wp-admin to http://WordPress.localhost/wp-admin.

Database

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

Restart Apache

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

Virtual Host Result

Final Words

That’s it! I hope you have a clear idea of setting up Virtual Hosts for WordPress with XAMPP running on Windows 10. If you have any query or suggestions, feel free to ask me via the comment section below.

Make Your WordPress Website 100% Faster.

Host it now on Cloudways WordPress Hosting Platform.

About Saud Razzak

Saud is the WordPress Community Manager at Cloudways - A Managed WooCommerce Hosting Platform. Saud is responsible for creating buzz, spread knowledge, and educate the people about WordPress in the Community around the globe. In his free time, he likes to play cricket and learn new things on the Internet. You can email him at m.saud@cloudways.com

Stay Connected:

You Might Also Like...