How to Create A Subdomain In Localhost Xampp?

6 minutes read

To create a subdomain in localhost XAMPP, you can start by opening the XAMPP control panel and making sure that Apache and MySQL services are running. Next, navigate to the "httpd-vhosts.conf" file located in the XAMPP installation directory. Open the file in a text editor and add a new VirtualHost block for your subdomain. Make sure to specify the subdomain name, document root, and other necessary configurations within the VirtualHost block. Save the changes and then edit the system hosts file to map the subdomain to the localhost IP address. Finally, restart the Apache server for the changes to take effect. You should now be able to access your subdomain in localhost XAMPP by entering the specified subdomain URL in your web browser.

Best Cloud Hosting Providers in 2024

1
DigitalOcean

Rating is 5 out of 5

DigitalOcean

2
AWS

Rating is 4.9 out of 5

AWS

3
Vultr

Rating is 4.8 out of 5

Vultr

4
Cloudways

Rating is 4.7 out of 5

Cloudways


How to create a subdomain for a specific project in xampp?

To create a subdomain for a specific project in XAMPP, you will need to follow these steps:

  1. Edit the hosts file:
  • Open the hosts file located at C:\Windows\System32\drivers\etc\hosts on Windows or /etc/hosts on Linux.
  • Add a new line at the end of the file in the following format: 127.0.0.1 subdomain.yourdomain.local, replacing subdomain with the desired subdomain and yourdomain with your actual domain name.
  1. Configure Apache virtual hosts:
  • Navigate to the Apache configuration directory, usually located at C:\xampp\apache\conf\extra\.
  • Open the httpd-vhosts.conf file in a text editor.
  • Add a new virtual host configuration block at the end of the file with the following content:
1
2
3
4
5
6
7
<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "C:/xampp/htdocs/yourprojectfolder"
    ServerName subdomain.yourdomain.local
    ErrorLog "logs/subdomain.yourdomain.local-error_log"
    CustomLog "logs/subdomain.yourdomain.local-access_log" common
</VirtualHost>


  • Replace subdomain.yourdomain.local with your subdomain and domain name, and C:/xampp/htdocs/yourprojectfolder with the path to your project folder.
  1. Restart Apache:
  • Open the XAMPP Control Panel.
  • Stop Apache and then start it again to apply the changes.
  1. Access your project:
  • Open a web browser and navigate to http://subdomain.yourdomain.local to access your project via the newly created subdomain.


By following these steps, you should now have a subdomain set up for your specific project in XAMPP.


How to create a wildcard subdomain in localhost xampp?

To create a wildcard subdomain in localhost XAMPP, you can follow these steps:

  1. Open the XAMPP control panel and make sure that Apache server is running.
  2. Navigate to the Apache configuration directory, which is typically located at "C:\xampp\apache\conf\extra".
  3. Open the "httpd-vhosts.conf" file in a text editor.
  4. Add the following code snippet to the file to create a wildcard subdomain:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
    ServerAlias *.localhost
    <Directory "C:/xampp/htdocs">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>


  1. Save the file and close the text editor.
  2. Restart the Apache server in the XAMPP control panel.
  3. Now, you can access any subdomain with the format "subdomain.localhost" in your web browser. For example, if you want to create a subdomain called "test", you can access it by entering "test.localhost" in the address bar.


By following these steps, you can create a wildcard subdomain in localhost XAMPP for testing your websites and applications.


How to redirect a subdomain to another page in xampp?

  1. Open the XAMPP control panel and start Apache if it is not already running.
  2. Navigate to the xampp/htdocs directory in the XAMPP installation folder.
  3. Create a new folder for the subdomain you want to redirect. For example, if you want to redirect subdomain.example.com, create a folder named subdomain.
  4. Create an index.php file inside the subdomain folder with the following code:
1
2
3
4
<?php
header("Location: http://example.com/newpage");
exit;
?>


Replace http://example.com/newpage with the URL of the page where you want to redirect the subdomain.

  1. Save the index.php file and close the text editor.
  2. Open your XAMPP installation folder and navigate to the apache\conf\extra directory.
  3. Open the httpd-vhosts.conf file in a text editor.
  4. Add the following lines at the end of the file:
1
2
3
4
<VirtualHost *:80>
    ServerName subdomain.example.com
    DocumentRoot "C:/xampp/htdocs/subdomain"
</VirtualHost>


Replace subdomain.example.com with the subdomain you want to redirect and C:/xampp/htdocs/subdomain with the path to the folder where you created the index.php file.

  1. Save the httpd-vhosts.conf file and close the text editor.
  2. Restart Apache in the XAMPP control panel to apply the changes.


Now, when you access subdomain.example.com in your web browser, it should redirect to the specified page.


How to access the subdomain control panel in xampp?

To access the subdomain control panel in XAMPP, you need to follow these steps:

  1. Open your web browser and type in the following URL: http://localhost/dashboard/
  2. This will take you to the XAMPP Dashboard where you can see a list of all the installed applications.
  3. Look for the subdomain control panel application, which will typically be listed as "phpMyAdmin" or "Webalizer" depending on the version of XAMPP you are using.
  4. Click on the subdomain control panel application link to access the control panel.
  5. Once you are in the control panel, you can manage your subdomains by creating, configuring, or deleting them as necessary.
  6. Remember to always secure your subdomains by setting appropriate permissions and adding any necessary security measures to prevent unauthorized access.


What is the purpose of creating a subdomain in localhost xampp?

Creating a subdomain in localhost XAMPP allows you to organize your projects and websites in a more systematic way. It can also be useful for testing multiple websites on the same localhost server without conflicts. Additionally, it mimics the structure of live websites with subdomains and can help in developing and testing websites before deploying them to a live server.

Facebook Twitter LinkedIn Telegram

Related Posts:

To configure a Laravel site on localhost using XAMPP, you first need to install XAMPP on your computer. After installing XAMPP, start the Apache and MySQL services from the XAMPP control panel. Then, download and install Composer on your computer if you haven&...
To install Joomla on XAMPP, you need to follow these steps:Download Joomla: Visit the Joomla website and download the latest version of Joomla.Install XAMPP: Download and install XAMPP onto your computer.Start XAMPP: Open the XAMPP Control Panel and start the ...
To run a Polymer project on XAMPP, you first need to have XAMPP installed on your computer. Once XAMPP is installed, you can create a new folder in the htdocs directory of your XAMPP installation and copy the contents of your Polymer project into this folder.N...