• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

TechLila

Bleeding Edge, Always

  • Home
  • About
  • Contact
  • Deals and Offers
Techlila Logo
Share
Tweet
Share
Pin
1 Shares
Font Awesome Iconic Font Exa
Up Next

Icon Fonts: Pros and Cons of the Font Awesome

Subdomains

TechLila Web Design and Development

How to Create Subdomain Using XAMPP

Avatar of Andor Nagy Andor Nagy
Last updated on: February 5, 2022

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 www.example.com/ but that’s just boring! How about creating a subdomain? Something like www.sub.example.com, now that looks like something, doesn’t it.

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: www.sub.domain.com the folder would be sub) or you can use the whole domain name for the folder name (ex: www.sub.domain.com the folder would be www.sub.domain.com).

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:

[html]
##<virtualhost *:80>
##ServerAdmin [email protected]
##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
##</virtualhost>
[/html]

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 sub.localhost.com. The final result would look something like the following:

[html]<virtualhost sub.localhost.com:80>
ServerAdmin [email protected] sub.localhost.com #DocumentRoot "C:/xampp/htdocs/ sub.localhost.com "
ServerName sub.localhost
ServerAlias www. sub.localhost.com
ErrorLog "logs/ sub.localhost.com -error.log"
CustomLog "logs/ sub.localhost.com -access.log" combined
</virtualhost>
[/html]

Registering the sub.localhost.com 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:

127.0.0.1 localhost
127.0.0.1 sub.localhost.com

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 sub.localhost.com 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.

Share
Tweet
Share
Pin
1 Shares

Disclosure: Content published on TechLila is reader-supported. We may receive a commission for purchases made through our affiliate links at no extra cost to you. Read our Disclaimer page to know more about our funding, editorial policies, and ways to support us.

Sharing is Caring

Share
Tweet
Share
Pin
1 Shares
Avatar of Andor Nagy

Andor Nagy

Andor Nagy is a 17 years old student, who is interested in modern technology, mostly web development and web design.

Category

  • Web Design and Development

Tags

XAMPP

Reader Interactions

What people are saying

  1. Avatar of TusharTushar

    Wow I love it. This will be more fun to create a subdomain on a localhost and work with it. Is there any way to create a subdomain in wampp.

    Reply
    • Avatar of Andor NagyAndor Nagy

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

      Regards,
      Andor Nagy

      Reply
  2. Avatar of Sai KumarSai Kumar

    Hi Andor Nagy, Awesome tutorial to create a sub domain using Xampp. I will surely try out to create one sub domain in localhost. Thanks for Sharing!!

    Reply
  3. Avatar of SadekSadek

    Nice tips, can I do the same with WAMP ??
    it’s slightly different from XAMPP

    Reply
    • Avatar of Rajesh NamaseRajesh Namase

      Andor already said that, you can use same method on WAMP too, if you’re facing any problems on WAMP let us know.

      Reply
      • Avatar of EmilyEmily

        It is good news that I can use the same method on WAMP! :) I’ll try it as soon as possible and will put it to my list to do (’cause I can forget).

        Reply
  4. Avatar of anshansh

    thnks for the help mate. . . it will be beneficial to create subdomain on localhost and then develop something.. :)

    Reply
  5. Avatar of ParmarParmar

    Thanks bro for this working tutorial, I was always wondering how the people get subdomain for their website, now I can also get one for my site! Thanks again!

    Reply
    • Avatar of Andor NagyAndor Nagy

      Hi, I’m glad it helped you! Note if you have a premium domain name, you need to create the subdomain at the service where you’ve both the domain and redirect it to your IP via the DNS manager.

      Regards,
      Andor Nagy

      Reply
  6. Avatar of Mohsin ShakeelMohsin Shakeel

    Well this tutorial is certainly interesting for me Rajesh Namase. BTW which theme you are using on this blog.

    Reply
    • Avatar of Rajesh NamaseRajesh Namase

      LOL Article is written by Andor Nagi :D We’re using custom Genesis child theme.

      Reply
  7. Avatar of yogeshyogesh

    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.

    Reply
  8. Avatar of Aliakbar FakhriAliakbar Fakhri

    Great Tip,
    just wanna know can I use the same method with Wamp???

    Reply
  9. Avatar of BhavikBhavik

    Thanks for this article..
    This article really helpful to people but how to create sub domain in wamp server ??

    Reply
    • Avatar of sridahrsridahr

      this is great tutoail but when ever i am adding this

      NameVirtualHost *:80

      DocumentRoot “D:/xampp/htdocs”
      ServerName localhost

      DocumentRoot “D:/xampp/htdocs/subdomain”
      ServerName subdomain.localhost.com

      My xammp server is not sratring

      Reply
  10. Avatar of Hiren RajputHiren Rajput

    Hi this is really great tutorial on how to create sub domain using xampp. Never think so that a sub domain can be made in localhost. Now I know the secrets and will also try it.

    Reply
  11. Avatar of michaelmichael

    hi, how do I do this on an actual website?

    Reply
    • Avatar of DonaldDonald

      I’m wondering the same thing. For me it redirects ALL the traffic to the subdomain now.

      Reply
  12. Avatar of Kyle E.Kyle E.

    Very nice tutorial, now after doing so of making sub.localhost.com is there away to make it be able to use for others like testdomain.tk? 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 sub.localhost.com go into sub.testdomain.com?

    Reply

Add Your Comment Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Popular

How to Increase Broadband Speed on Windows

10 Best Android Launchers of 2021

Things to Do After Installing Windows 10 – Windows 10 Tips and Tricks

Top 10 Search Engines You Can Use to Search the Web Privately

55 Interesting Computer Facts That Will Blow Your Mind

What to Look for When Buying a Laptop – A Laptop Buying Guide

Fusion Drive Vs SSD – Things Nobody Tells you About Fusion vs SSD Storage

Useful Tools

• Grammarly – Free Grammar Checker
• SEMrush – The Best SEO Tool Trusted by Experts
• Setapp – One-stop subscription for Mac and iOS

Trending Topics

  • Android
  • Internet
  • iPhone
  • Linux
  • Macintosh
  • Security
  • Social Media
  • Technology
  • Windows

Worth Checking

10 Best Sound Equalizer for Windows 10 (2022 Edition!)

14 Best VLC Skins that are Highly Recommended and Free

Footer Logo Footer Text Logo

Footer

About

Hello and welcome to TechLila, the famous technology blog where you can find resourceful articles for mastering the basics and beyond.

At TechLila, our main goal is to provide unique information, such as quality tips and tricks, tutorials, how-to guides on Windows, Macintosh, Linux, Android, iPhone, Security and a few miscellaneous sub-topics such as reviews.

Links

  • About
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms

Follow

Custom Theme Using Genesis Framework

Cloud hosting by Cloudways

Language

en English
bg Българскиzh-CN 简体中文nl Nederlandsen Englishtl Filipinofr Françaisde Deutschid Bahasa Indonesiait Italianoja 日本語pl Polskipt Portuguêsro Românăru Русскийsr Српски језикes Españolsv Svenskatr Türkçeuk Українськаvi Tiếng Việt

© Copyright  2012–2023 TechLila. All Rights Reserved.