Add subdomains to a XAMPP server on Windows
09 Mar 2016In this post you’ll learn how to add subdomains to a XAMPP Server.
- Choose a subdomain. For this example I’ll use
test
, which will produce the URLtest.localhost.com
- Create a new directory in
C:\xampp\htdocs
with the name of your subdomain (e.g.C:\xampp\htdocs\test
) - Create an
index.html
file in the new directory. This is your subdomain index page - Find your root XAMPP directory. This will probably be
C:\xampp
- From your XAMPP root, go to
apache\conf\extra
(e.g.C:\xampp\apache\conf\extra
) -
Make a copy of
httpd-vhosts.conf
, as shown below: - Open the original file
httpd-vhosts.conf
in a text editor -
Copy the code below, and paste it at the bottom of
http-vhosts.conf
:#main domain <virtualhost *:80=""> ServerAdmin webmaster@test.localhost.com DocumentRoot "C:/xampp/htdocs/" ServerName localhost ServerAlias www.localhost.com ErrorLog "logs/localhost.com-error.log" CustomLog "logs/localhost.com-access.log" common </virtualhost> #test sub-domain <virtualhost *:80=""> ServerAdmin webmaster@test.localhost.com DocumentRoot "C:/xampp/htdocs/test" ServerName test.localhost ServerAlias www.test.localhost.com ErrorLog "logs/test.localhost.com-error.log" CustomLog "logs/test.localhost.com-access.log" common </virtualhost>
- Replace
test
with your subdomain name -
Go to
C:\Windows\System32\drivers\etc
, as shown below - Create a copy of
hosts
-
At the bottom of the file add the following code:
127.0.0.1 test.localhost.com
- Replace
test
with your subdomain name
Congratulations, You’ve created a new subdomain!
Now, restart your server from the XAMPP control panel and visit your new subdomain in your browser to check it’s working.
You can use this technique to add subdomains to a XAMPP Server anytime you want. I’ve got ten at the moment!
Any problems, leave a comment and I’ll try to help.