Subdomain in localhost using Apache Xampp

Today, we’re sharing how to create subdomain in localhost using Apache Xampp. Following our tutorial, you can Create multiple Subdomain in localhost using Apache Xampp.

Requirement:

  • Xampp Pre-installed (Latest Version)
  • Administrator privileges
  • Notepad++ (Optional)

Method:

  1. First of all stop Apache, if running through XAMPP Control Panel.

xampp-control-panel

  1. Now navigate to following directory
C:\xampp\apache\conf\extra

apache-xampp-configuration

  1. Now open httpd-vhosts.conf file using Notepad++ Editor. Please copy the file as backup before editing the core file
  2. Add the following lines in the end of the your file. Change example to your subdomain
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/example"
ServerName example.localhost.com
</VirtualHost>

Subdomain in localhost using Apache Xampp

  1. Now save the file or Press Ctrl+S
  2. Now open Notepad or Notepad++ as an Administrator
  3. open the following file
C:\Windows\System32\drivers\etc\hosts

Subdomain in localhost using Apache Xampp

  1. Add the following code to your hosts file
127.0.0.1 example.localhost.com
  1. Change example to your subdomain. Now save the file.
  2. Start the Apache Server using Xampp Control Panel
  3. Navigate to your subdomain like example.localhost.com
  4. Your subdomain is ready
  5. To create another Subdomain in localhost using Apache Xampp, just Add the following code to httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/example1"
ServerName example1.localhost.com
</VirtualHost>
  1. and following code to your Hosts file
127.0.0.1 example1.localhost.com
  1. To create multiple Subdomain in localhost using Apache Xampp, repeat step 13 & Step 14

If you like this, please share this to social networks. Have a nice day!