How to Configure Virtual Host on Windows 10 XAMPP

How to Configure Virtual Host on Windows 10 XAMPP

Create the Virtual Host

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

Apache location

Then, 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:

  1. <VirtualHost *:80>
  2. DocumentRoot “c:/xampp/htdocs/WordPress”
  3. ServerName WordPress.localhost
  4. <Directory “c:/xampp/htdocs/WordPress”>
  5. </Directory>
  6. </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 “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:

  1. C:\Windows\System32\drivers\etc\hosts
Run

Next, open Host file in your text editor.

Host File

Add the following line in the Host file.

  1. 127.0.0.1 WordPress.localhost
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.

Set 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 configure 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 site URL 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.

Leave a Reply