Many developers start development in 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 and configure virtual hosts for WordPress websites with XAMPP running 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.
Then, edit httpd-vhosts.conf with any text editor. In my case, I am using Notepad++.
The file looks something like this:
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:
Next, open Host file in your text editor.
Add the following line in the Host file.
Once you are done, check whether wordpress.localhost opens up in your browser.
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 configure virtual host).
For this, go to http://localhost/phpmyadmin/ and select your database. In my case, it is “WordPress”.
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.
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.
Since the setup of Virtual Hosts for WordPress Website with XAMPP is done, here is what the final results would look like:
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.
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 email@example.com
Make Your WordPress Website 100% Faster.
Host it now on Cloudways WordPress Hosting Platform.