How to Create Subdomain in XAMPP
- Sunday, December 14, 2025
Creating a subdomain in XAMPP involves configuring two main files: your XAMPP installation's Apache HTTP Server configuration and your operating system's hosts file.
Here is a step-by-step guide on how to set up a subdomain like sub.localhost for your project:

1. Configure Apache's Virtual Hosts
The Virtual Host configuration tells Apache how to handle requests for your new subdomain.
- Locate the
httpd-vhosts.conffile: Navigate to the following path in your XAMPP installation directory:
(The path might be different if XAMPP is installed elsewhere, but the relative pathC:\xampp\apache\conf\extra\httpd-vhosts.conf\apache\conf\extra\remains the same). - Open and Edit the file: Open
httpd-vhosts.confusing a text editor (like Notepad++, VS Code, or Sublime Text). - Add the new Virtual Host entry: Append the following block of code to the end of the file. Make sure to replace
your_project_namewith the actual folder name of your project within thehtdocsdirectory.*Note: I recommend keeping your mainlocalhostconfiguration intact for general use*.<VirtualHost *:80> DocumentRoot "C:/xampp/htdocs/your_project_name" ServerName sub.localhost <Directory "C:/xampp/htdocs/your_project_name"> Order allow,deny Allow from all Require all granted </Directory> </VirtualHost> DocumentRoot: This is the absolute path to the folder that contains your project files. This will be the root directory for yoursub.localhostdomain.ServerName: This is the actual name of your desired subdomain (e.g.,blog.localhost,dev.localhost,sub.localhost).
2. Edit the Hosts File (DNS Simulation)
The hosts file is what your computer uses to map domain names to IP addresses. Editing it will tell your operating system that sub.localhost should point back to your local machine (127.0.0.1).
- Locate the
hostsfile: The location varies by OS:- Windows:
C:\Windows\System32\drivers\etc\hosts - macOS/Linux:
/etc/hosts
- Windows:
- Open and Edit the file with Administrator/Root privileges: This is crucial! You must open your text editor as an administrator (right-click -> "Run as administrator" on Windows) before opening the hosts file, or you won't be able to save your changes.
- Add the mapping: Add the following line to the end of the file:
127.0.0.1 sub.localhost 127.0.0.1is the loopback address, meaning "this computer".sub.localhostis the subdomain name you defined in the Virtual Host configuration.
3. Restart Apache
For the changes to take effect, you must restart your Apache server in the XAMPP Control Panel.
- Open the XAMPP Control Panel.
- Click the Stop button next to the Apache module.
- Click the Start button to restart it.
4. Test the Subdomain
- Open your web browser and navigate to:
http://sub.localhost/. - If everything is configured correctly, you should now see the content of your project folder (
C:/xampp/htdocs/your_project_name).