In the Installing Apache HTTP Server on Windows tutorial, we learned how to configure an Apache HTTP Server web server. This tutorial covers setting up multiple subdomains, referred to in Apache as virtual hosts.
In this tutorial:
Required knowledge:
See also:
Setup
This tutorial outlines how I host multiple WordPress websites on my dev box. Each subdomain, or virtual host, can be configured separately using separate configuration files.
Each subdomain has a separate folder in htdocs:
htdocs
⊢ alphacompany
∟ bravocompany
On your dev box, these two subdomains would be available at:
- alphacompany.localhost
- bravocompany.localhost
Configure
Configuration is done in a text file called httpd-vhosts.conf. Config files are simple text files containing all the configuration details required for the server to work on your computer.
httpd-vhosts.conf
Lines preceded by a # are comments.
C
⊢ Apache24
⊢ htdocs
∟ conf
∟ httpd.conf
∟ extra
∟ httpd-vhosts.conf
You will now want to configure the two subdomains using <VirtualHost>
directives (note I have added a third subdomain for phpMyAdmin as well):
# # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The first VirtualHost section is used for all requests that do not # match a ServerName or ServerAlias in any <VirtualHost> block. # <VirtualHost *:80> ServerAdmin david@stylus.co.za DocumentRoot "${SRVROOT}/htdocs" ServerName localhost ServerAlias localhost ErrorLog "logs/localhost-error.log" CustomLog "logs/localhost-access.log" common </VirtualHost> <VirtualHost *:80> ServerAdmin david@stylus.co.za DocumentRoot "${SRVROOT}/htdocs/stylus" ServerName alphacompany.localhost ServerAlias bravocompany.localhost </VirtualHost> ################################# <VirtualHost *:80> ServerAdmin david@cape-hike.co.za DocumentRoot "${SRVROOT}/htdocs/cape-hike" ServerName cape-hike. Localhost ServerAlias cape-hike.localhost </VirtualHost> <VirtualHost *:80> ServerAdmin david@stylus.co.za DocumentRoot "${SRVROOT}/htdocs/phpMyAdmin" ServerName phpMyAdmin. Localhost ServerAlias phpMyAdmin. Localhost </VirtualHost> <VirtualHost *:80> ServerAdmin david@stylus.localhost DocumentRoot "${SRVROOT}/htdocs/PHPWebAdmin" ServerName PHPWebAdmin.localhost ServerAlias PHPWebAdmin.localhost ErrorLog "logs/PHPWebAdmin.localhost-error.log" CustomLog "logs/PHPWebAdmin.localhost-access.log" common </VirtualHost>
Restart Apache
You will always have to restart Apache once you have made and saved changes to any of the config files.

References:
- Apache Lounge. (no date) Apache 2 Server on Windows for (business) webmasters, developers, home users and programmers. Available at: https://www.apachelounge.com/ (Accessed: 10 June 2024).