If you are a WordPress plugin or WordPress theme developer, or provide professional WordPress support from time to time you need to run multiple WordPress websites on the same XAMPP installation on Windows. Multiple websites running on the same Apache web server are called Virtual Hosts. In this easy to follow tutorial we explain how to setup multiple virtual hosts on XAMPP so you can run multiple WordPress websites on the same XAMPP installation.
Configure Virtual Hosts in XAMPP
- To add virtual hosts in XAMPP, or in other words, to configure multiple websites on XAMPP, open the Virtual Hosts Apache configuration file httpd-vhosts.conf from C:\xampp\apache\conf\extra\
- Uncomment the below line to enable name based virtual hosts on your XAMPP.
- At the end of the file add the following 4 lines. These 4 lines are used to allow access to the XAMPP configuration pages (to access phpMyAdmin etc) by using the URL http://localhost
<VirtualHost *> DocumentRoot "C:\XAMPP\htdocs" ServerName localhost </VirtualHost>
- For each other virtual host (website) you would like to configure on the XAMPP Apache web server, add the below code (using www.wpwhitesecurity.com as example).
<VirtualHost *> DocumentRoot "C:\XAMPP\htdocs\wppro" ServerName www.WPWhiteSecurity.com <Directory "C:\XAMPP\htdocs\wppro"> Options Indexes FollowSymLinks Includes ExecCGI Order allow,deny Allow from all </Directory> </VirtualHost>
- By adding the above directives to httpd-vhosts.conf (XAMPP virtual hosts configuration file), the Apache web server running on XAMPP knows that:
- The website files can be found in c:\xampp\htdocs\wppro (line 2)
- This website should respond to www.wpwhitesecurity.com (line 3)
- Allow everyone to access the content of the directory (line 4 to 7)
- To test and confirm that all the syntax in the Apache configuration is correct, run the httpd.exe process with the –t switch from the c:\xampp\apache\bin directory as seen in the below screenshot.
Configure the Windows Hosts File
Use the Windows Hosts file to redirect the traffic from your computer to the local installation of XAMPP rather than to the original website. E.g. while testing new WordPress changes for our website WP White Security.com, I add an entry in the Windows Hosts file to redirect requests from my browser to the local intallation of XAMPP. To learn on how to redirect traffic using Windows Hosts file, read our webmaster tip Configuring Windows Host Files.
Configuration example: Running multiple websites on XAMPP
If you would like to add more than one virtual host (website) to XAMPP, simple add more VirtualHost directives to the same file. In my testing environment I have the following websites set up:
- www.WP White Security.com from c:\xampp\htdocs\wppro
- www.wphandymen.com from c:\xampp\htdocs\wphandy
To have both websites and the XAMPP configuration pages (localhost) running on my XAMPP installation, I have the following in the XAMPP virtual hosts configuration file (httpd-vhosts.conf).
<VirtualHost *> DocumentRoot "C:\XAMPP\htdocs" ServerName localhost </VirtualHost> <VirtualHost *> DocumentRoot "C:\XAMPP\htdocs\wppro" ServerName www.WPWhiteSecurity.com <Directory "C:\xampp\htdocs\wppro"> Order allow,deny Allow from all </Directory> </VirtualHost> <VirtualHost *> DocumentRoot "C:\XAMPP\htdocs\wphandy" ServerName www.wphandymen.com <Directory "C:\xampp\htdocs\wphandy"> Order allow,deny Allow from all </Directory> </VirtualHost>