Skip to content

Instantly share code, notes, and snippets.

@adojos
Last active September 30, 2022 22:47
Show Gist options
  • Save adojos/9507e8ab36b636e04a31f37a02c9766e to your computer and use it in GitHub Desktop.
Save adojos/9507e8ab36b636e04a31f37a02c9766e to your computer and use it in GitHub Desktop.
XAMPP | Apache: Config for 'httpd-vhosts.conf' Implementing multi-ports and multi-virtualHosts [Part 3 of 4]

[Part 3 of 4] Apache Multi-Port & Multi-Host 'httpd-vhosts.conf'


In order to have a multi-port configuration for different virtual hosts (projects, websites) on Apache in XAMPP, you need to make changes to the following 3 Apache configuration files and 1 windows host file:

1. httpd.conf (\XAMPP\apache\conf)

2. httpd-ssl.conf (\XAMPP\apache\conf\extra)

3. httpd-vhosts.conf (\XAMPP\apache\conf\extra) 👇 This file 👇

4. Windows 'hosts' file (C:\Windows\System32\drivers\etc)


👉 Target Scenario:

1) Implement 4 named and independent Virtual Hosts
2) Implement 4 different HTTP ports for above Virtual Hosts (8081, 8083, 8085, 8087)
3) Implement 4 different HTTPS ports for above Virtual Hosts (8082, 8084, 8086, 8088)

Checkout the following gist links for complete changes to above configuration files each:

1. [Part 1 of 4] Apache Multi-Port & Multi-Host 'httpd.conf' Config

2. [Part 2 of 4] Apache Multi-Port & Multi-Host 'httpd-ssl.conf' Config

3. [Part 3 of 4] Apache Multi-Port & Multi-Host 'httpd-vhosts.conf'

4. [Part 4 of 4] Apache Multi-Port & Multi-Host Windows hosts file Config


httpd-vhosts.conf (\XAMPP\apache\conf\extra)

Note the changes done for following directives in this file:

(a) HTTP VirtualHost *: 80
(b) HTTPS VirtualHost *: 443

👉 NOTE: Do not copy the whole file 'as-is', because it has been lifted from my production environment and may have hard-coded directory paths. I recommend only to refer the quoted key changes/modifications


# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
##NameVirtualHost *:80
NameVirtualHost *:8081
#
# 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 webmaster@dummy-host.example.com
    ##DocumentRoot "D:/DEV-WORKSPACE/XAMPP/htdocs/dummy-host.example.com"
    ##ServerName dummy-host.example.com
    ##ServerAlias www.dummy-host.example.com
    ##ErrorLog "logs/dummy-host.example.com-error.log"
    ##CustomLog "logs/dummy-host.example.com-access.log" common
##</VirtualHost>

##<VirtualHost *:80>
    ##ServerAdmin webmaster@dummy-host2.example.com
    ##DocumentRoot "D:/DEV-WORKSPACE/XAMPP/htdocs/dummy-host2.example.com"
    ##ServerName dummy-host2.example.com
    ##ErrorLog "logs/dummy-host2.example.com-error.log"
    ##CustomLog "logs/dummy-host2.example.com-access.log" common
##</VirtualHost>


#####################################################################
## DEFAULT FALLBACK VIRTUAL HOST CONFIG FOR UNMATCHED HTTP/S REQUESTS
######################################################################

<VirtualHost *:8081>
 DocumentRoot "D:/DEV-WORKSPACE/XAMPP/htdocs/"
 ServerName localhost
</VirtualHost>

<VirtualHost *:8082>
 DocumentRoot "D:/DEV-WORKSPACE/XAMPP/htdocs/"
 ServerName localhost
 SSLEngine On
 SSLCertificateFile "D:/DEV-WORKSPACE/XAMPP/apache/conf/ssl.crt/server.crt"
 SSLCertificateKeyFile "D:/DEV-WORKSPACE/XAMPP/apache/conf/ssl.key/server.key"
</VirtualHost>


##########################################################
## VIRTUAL HOST HTTP CONFIG FOR PROJECT 1 - website1 http
##########################################################

<VirtualHost website1:8081>
    ServerAdmin webmaster@website1.com
    DocumentRoot "D:/DEV-WORKSPACE/XAMPP/htdocs/website1"
    ServerName website1
	ServerAlias www.website1
    ErrorLog "logs/website1-error.log"
    CustomLog "logs/website1-access.log" common
	<Directory "D:/DEV-WORKSPACE/XAMPP/htdocs/website1">
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>


##########################################################
## VIRTUAL HOST HTTPS CONFIG FOR PROJECT 1 - website1 https
##########################################################

<VirtualHost website1:8082>
    ServerAdmin webmaster@website1.com
    DocumentRoot "D:/DEV-WORKSPACE/XAMPP/htdocs/website1"
    ServerName website1
	ServerAlias www.website1
	SSLEngine On
	SSLCertificateFile "D:/DEV-WORKSPACE/XAMPP/apache/conf/ssl.crt/server.crt"
	SSLCertificateKeyFile "D:/DEV-WORKSPACE/XAMPP/apache/conf/ssl.key/server.key"
    ErrorLog "logs/website1-error.log"
    CustomLog "logs/website1-access.log" common
	<Directory "D:/DEV-WORKSPACE/XAMPP/htdocs/website1">
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>


##########################################################
## VIRTUAL HOST HTTP CONFIG FOR PROJECT 2 - website2 http
##########################################################

<VirtualHost website2:8081>
    ServerAdmin webmaster@website2.com
    DocumentRoot "D:/DEV-WORKSPACE/XAMPP/htdocs/website2"
    ServerName website2
	ServerAlias www.website2
    ErrorLog "logs/website1-error.log"
    CustomLog "logs/website1-access.log" common
	<Directory "D:/DEV-WORKSPACE/XAMPP/htdocs/website2">
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>


##########################################################
## VIRTUAL HOST HTTPS CONFIG FOR PROJECT 2 - website2 https
##########################################################

<VirtualHost website2:8082>
    ServerAdmin webmaster@website2.com
    DocumentRoot "D:/DEV-WORKSPACE/XAMPP/htdocs/website2"
    ServerName website2
	ServerAlias www.website2
	SSLEngine On
	SSLCertificateFile "D:/DEV-WORKSPACE/XAMPP/apache/conf/ssl.crt/server.crt"
	SSLCertificateKeyFile "D:/DEV-WORKSPACE/XAMPP/apache/conf/ssl.key/server.key"
    ErrorLog "logs/website1-error.log"
    CustomLog "logs/website1-access.log" common
	<Directory "D:/DEV-WORKSPACE/XAMPP/htdocs/website1">
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>


##########################################################
## VIRTUAL HOST HTTP CONFIG FOR automationdojos-demo http
##########################################################

<VirtualHost automationdojos-demo:8081>
    ServerAdmin admin@automationdojos-demo.com
    DocumentRoot "D:/DEV-WORKSPACE/XAMPP/htdocs/automationdojos-demo"
    ServerName automationdojos-demo
	ServerAlias www.automationdojos-demo
    ErrorLog "logs/website1-error.log"
    CustomLog "logs/website1-access.log" common
	<Directory "D:/DEV-WORKSPACE/XAMPP/htdocs/automationdojos-demo">
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>


##########################################################
## VIRTUAL HOST HTTPS CONFIG FOR automationdojos-demo https
##########################################################

<VirtualHost automationdojos-demo:8082>
    ServerAdmin admin@automationdojos-demo.com
    DocumentRoot "D:/DEV-WORKSPACE/XAMPP/htdocs/automationdojos-demo"
    ServerName automationdojos-demo
	ServerAlias www.automationdojos-demo
	SSLEngine On
	SSLCertificateFile "D:/DEV-WORKSPACE/XAMPP/apache/conf/ssl.crt/server.crt"
	SSLCertificateKeyFile "D:/DEV-WORKSPACE/XAMPP/apache/conf/ssl.key/server.key"
    ErrorLog "logs/website1-error.log"
    CustomLog "logs/website1-access.log" common
	<Directory "D:/DEV-WORKSPACE/XAMPP/htdocs/automationdojos-demo">
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>


##########################################################
## VIRTUAL HOST HTTP CONFIG FOR automationdojos-dev http
##########################################################

<VirtualHost automationdojos-dev:8083>
    ServerAdmin admin@automationdojos-dev.com
    DocumentRoot "D:/DEV-WORKSPACE/XAMPP/htdocs/automationdojos-dev"
    ServerName automationdojos-dev
	ServerAlias www.automationdojos-dev
    ErrorLog "logs/website1-error.log"
    CustomLog "logs/website1-access.log" common
	<Directory "D:/DEV-WORKSPACE/XAMPP/htdocs/automationdojos-dev">
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>


##########################################################
## VIRTUAL HOST HTTPS CONFIG FOR automationdojos-dev https
##########################################################

<VirtualHost automationdojos-dev:8084>
    ServerAdmin admin@automationdojos-dev.com
    DocumentRoot "D:/DEV-WORKSPACE/XAMPP/htdocs/automationdojos-dev"
    ServerName automationdojos-dev
	ServerAlias www.automationdojos-dev
	SSLEngine On
	SSLCertificateFile "D:/DEV-WORKSPACE/XAMPP/apache/conf/ssl.crt/server.crt"
	SSLCertificateKeyFile "D:/DEV-WORKSPACE/XAMPP/apache/conf/ssl.key/server.key"
    ErrorLog "logs/website1-error.log"
    CustomLog "logs/website1-access.log" common
	<Directory "D:/DEV-WORKSPACE/XAMPP/htdocs/automationdojos-dev">
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>



##########################################################
## VIRTUAL HOST HTTP CONFIG FOR automationdojos-prod http
##########################################################

<VirtualHost automationdojos-prod:8085>
    ServerAdmin admin@automationdojos-prod.com
    DocumentRoot "D:/DEV-WORKSPACE/XAMPP/htdocs/automationdojos-prod"
    ServerName automationdojos-prod
	ServerAlias www.automationdojos-prod
    ErrorLog "logs/website1-error.log"
    CustomLog "logs/website1-access.log" common
	<Directory "D:/DEV-WORKSPACE/XAMPP/htdocs/automationdojos-prod">
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>


##########################################################
## VIRTUAL HOST HTTPS CONFIG FOR automationdojos-prod https
##########################################################

<VirtualHost automationdojos-prod:8086>
    ServerAdmin admin@automationdojos-prod.com
    DocumentRoot "D:/DEV-WORKSPACE/XAMPP/htdocs/automationdojos-prod"
    ServerName automationdojos-prod
	ServerAlias www.automationdojos-prod
	SSLEngine On
	SSLCertificateFile "D:/DEV-WORKSPACE/XAMPP/apache/conf/ssl.crt/server.crt"
	SSLCertificateKeyFile "D:/DEV-WORKSPACE/XAMPP/apache/conf/ssl.key/server.key"
    ErrorLog "logs/website1-error.log"
    CustomLog "logs/website1-access.log" common
	<Directory "D:/DEV-WORKSPACE/XAMPP/htdocs/automationdojos-prod">
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>


##########################################################
## VIRTUAL HOST HTTP CONFIG FOR wordpress-vanilla http
##########################################################

<VirtualHost wordpress-vanilla:8087>
    ServerAdmin admin@wordpress-vanilla.com
    DocumentRoot "D:/DEV-WORKSPACE/XAMPP/htdocs/wordpress-vanilla"
    ServerName wordpress-vanilla
	ServerAlias www.wordpress-vanilla
    ErrorLog "logs/website1-error.log"
    CustomLog "logs/website1-access.log" common
	<Directory "D:/DEV-WORKSPACE/XAMPP/htdocs/wordpress-vanilla">
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>


##########################################################
## VIRTUAL HOST HTTPS CONFIG FOR wordpress-vanilla https
##########################################################

<VirtualHost wordpress-vanilla:8088>
    ServerAdmin admin@wordpress-vanilla.com
    DocumentRoot "D:/DEV-WORKSPACE/XAMPP/htdocs/wordpress-vanilla"
    ServerName wordpress-vanilla
	ServerAlias www.wordpress-vanilla
	SSLEngine On
	SSLCertificateFile "D:/DEV-WORKSPACE/XAMPP/apache/conf/ssl.crt/server.crt"
	SSLCertificateKeyFile "D:/DEV-WORKSPACE/XAMPP/apache/conf/ssl.key/server.key"
    ErrorLog "logs/website1-error.log"
    CustomLog "logs/website1-access.log" common
	<Directory "D:/DEV-WORKSPACE/XAMPP/htdocs/wordpress-vanilla">
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment