How to Create Sub-Domains Using XAMPP

How to Create Sub-Domains Using XAMPP

In the previous article we’ve been talking about how to set up XAMPP on your local PC and how to install WordPress on it. But what if you want to have multiple websites on your local server? You could simply create new folders and open them as but that’s just boring! How about creating a subdomain? Something like, now that looks like something, doesn’t it.

Create Subdomains Using XAMPP

Creating a Root Directory Folder for the Subdomin

Let’s see how we do all this stuff. Firstly you want to create the root directory of the new subdomain. Go to C:/xampp/htdocs (this might be different for you depending where you installed XAMPP). The folder’s name can be just the subdomain name (ex: the folder would be sub) or you can use the whole domain name for the folder name (ex: the folder would be

Creating the Subdomain

To create the subdomain for you localhost you need to edit a XAMPP configuration file named httpd-vhosts.conf this file is located in C:/xampp/apache/conf/extra (this might be different for you depending where you installed XAMPP). Open up the httpd-vhosts.conf with your favorite text editor and look for the following:

##<virtualhost *:80>
    ##ServerAdmin postmaster@dummy-host.localhost
    ##DocumentRoot "C:/xampp/htdocs/dummy-host.localhost"
    ##ServerName dummy-host.localhost
    ##ServerAlias www.dummy-host.localhost
    ##ErrorLog "logs/dummy-host.localhost-error.log"
    ##CustomLog "logs/dummy-host.localhost-access.log" combined

Duplicate it and remove the ## from before each line, then we are ready to create the subdomain, in our case it will be sub.localhost of course you can make your whatever you would like to. Change the * to sub.localhost and on each line where it says dummy-host.localhost to The final result would look something like the following:

    ServerAdmin postmaster@  #DocumentRoot "C:/xampp/htdocs/ "
    ServerName sub.localhost
    ServerAlias www.
    ErrorLog "logs/ -error.log"
    CustomLog "logs/ -access.log" combined

Registering the Domain

If you are done with this, you need to register your subdomain, in the Window’s hosts file. This can be found in C:/Windows/System32/drivers/etc. Create a backup of the hosts file then open it with your favorite text editor and add the following lines at the bottom: localhost

Note: Windows 7 or Windows 8 doesn’t allow you to edit that file, to edit that file first copy it to other location say Desktop then edit it in your favourite editor and then paste (replace) edited file in etc folder.

This will create you a domain. If you are done with this and you are 100% sure you did everything right, restart your apache using the control panel of XAMPP (stop/start). After you restarted the Apache, you should be able to access your new subdomain:

If you XAMPP freezes when you want to restart the Apache, make sure that you are not using any HTTP:// or / on the end of the domain you wish to create a directory for. If you have any other questions regarding to this topic, feel free to ask in the comments below.


    • Andor Nagy says

      Hi. I’m sure it is possible. Through I never used WAMP, but as I read it’s the same as on XAMPP.

      Andor Nagy

  1. yogesh says

    This articles is very helpful to me but I want to know about something new technology like Joomla etc. Please Write some articles on that.

    • says

      this is great tutoail but when ever i am adding this

      NameVirtualHost *:80

      DocumentRoot “D:/xampp/htdocs”
      ServerName localhost

      DocumentRoot “D:/xampp/htdocs/subdomain”

      My xammp server is not sratring

  2. Kyle E. says

    Very nice tutorial, now after doing so of making is there away to make it be able to use for others like I used the httpd-vhosts.conf before setting up multiple folders so I can have more than just one folder htdocs hold so much. Is there away I can make the go into

 Comment Policy

Your words are your own, so be nice and helpful if you can. Please, only use your REAL NAME, not your business name or keywords. Using business name or keywords instead of your real name will lead to the comment being deleted. Anonymous commenting is not allowed either. Limit the amount of links submitted in your comment. We accept clean XHTML in comments, but don't overdo it please. You can wrap code in [lang-name][/lang-name] tags.

Tell us what you're thinking...

If you want a picture to show with your comment, then get Gravatar!

CommentLuv badge