How to Enable Virtualhost In Xampp>

5 minutes read

To enable virtual hosts in XAMPP, you need to locate and edit the Apache configuration file called httpd.conf. This file is usually found in the "conf" folder within the XAMPP installation directory. Within this file, you need to uncomment the line that includes the following text: "Include conf/extra/httpd-vhosts.conf" by removing the "#" symbol at the beginning of the line.


Next, you need to open the "httpd-vhosts.conf" file within the "extra" folder in the XAMPP installation directory. In this file, you can define your virtual hosts by specifying the DocumentRoot and ServerName for each virtual host. Make sure to also update the Windows hosts file located in "C:\Windows\System32\drivers\etc" to map the domain names of the virtual hosts to localhost.


Finally, restart the Apache server in XAMPP for the changes to take effect. You should now be able to access your websites using the defined domain names specified in the virtual host configuration.


How to create a new virtual host in XAMPP?

To create a new virtual host in XAMPP, follow these steps:

  1. Open the "httpd-vhosts.conf" file located in the "conf/extra" directory of your XAMPP installation folder (e.g. C:/xampp/apache/conf/extra).
  2. Add a new VirtualHost configuration block to the file. Below is an example of a VirtualHost configuration block:
1
2
3
4
5
6
7
8
9
<VirtualHost *:80>
    ServerName yourdomain.local
    DocumentRoot "C:/xampp/htdocs/yourprojectfolder"
    <Directory "C:/xampp/htdocs/yourprojectfolder">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>


  1. Replace "yourdomain.local" with the domain name you want to use for your virtual host and replace "C:/xampp/htdocs/yourprojectfolder" with the path to the root directory of your project.
  2. Save the changes to the "httpd-vhosts.conf" file.
  3. Open the "hosts" file located in the "C:\Windows\System32\drivers\etc" directory (you may need to run your text editor as an administrator to open this file).
  4. Add an entry for your domain name pointing to 127.0.0.1. Below is an example of an entry:
1
127.0.0.1 yourdomain.local


  1. Save the changes to the "hosts" file.
  2. Restart the Apache server in XAMPP.
  3. Open a web browser and navigate to your domain name (e.g. http://yourdomain.local) to test the new virtual host.


Your new virtual host should now be set up and accessible in XAMPP.


How to disable a virtual host in XAMPP?

To disable a virtual host in XAMPP, you will need to edit the Apache configuration file. Here's how you can do it:

  1. Open the XAMPP control panel and stop the Apache server.
  2. Navigate to the "httpd-vhosts.conf" file which is usually located in the "conf" folder within the XAMPP installation directory. The exact path may vary depending on your operating system.
  3. Open the "httpd-vhosts.conf" file in a text editor.
  4. Locate the entry for the virtual host you want to disable. It should look something like this:
1
2
3
4
5
6
7
8
9
<VirtualHost *:80>
    ServerName example.com
    DocumentRoot "C:/xampp/htdocs/example"
    <Directory "C:/xampp/htdocs/example">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>


  1. To disable the virtual host, simply comment out the entire block by adding a "#" at the beginning of each line, like this:
1
2
3
4
5
6
7
8
9
#<VirtualHost *:80>
#    ServerName example.com
#    DocumentRoot "C:/xampp/htdocs/example"
#    <Directory "C:/xampp/htdocs/example">
#        Options Indexes FollowSymLinks
#        AllowOverride All
#        Require all granted
#    </Directory>
#</VirtualHost>


  1. Save the changes to the file.
  2. Start the Apache server from the XAMPP control panel.


Now the virtual host should be disabled, and its configuration will no longer be loaded by Apache.


How to access virtual hosts from the browser in XAMPP?

To access virtual hosts from the browser in XAMPP, you will need to edit the Apache configuration file and set up the virtual hosts. Here is a step-by-step guide on how to do this:

  1. Open the Apache configuration file httpd.conf located in the \xampp\apache\conf directory.
  2. Uncomment the following line by removing the ' # ' at the beginning of the line:
1
# Include conf/extra/httpd-vhosts.conf


  1. Save the changes and close the file.
  2. Open the file httpd-vhosts.conf located in the \xampp\apache\conf\extra directory.
  3. Add the following code to set up a virtual host:
1
2
3
4
5
6
7
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot "C:/xampp/htdocs/yourproject"
    ServerName yourproject.local
    ErrorLog "logs/yourproject-error.log"
    CustomLog "logs/yourproject-access.log" common
</VirtualHost>


Replace "yourproject" with the name of your project directory and update the DocumentRoot path accordingly.

  1. Save the changes and close the file.
  2. Open the hosts file located in C:\Windows\System32\drivers\etc directory with a text editor (e.g., Notepad) with administrator privileges.
  3. Add the following line at the end of the file:
1
127.0.0.1    yourproject.local


Replace "yourproject" with the ServerName specified in the VirtualHost configuration.

  1. Save the changes and close the file.
  2. Restart the Apache server in XAMPP.
  3. Now you should be able to access your virtual host from the browser by typing http://yourproject.local in the address bar.


By following these steps, you can set up and access virtual hosts in XAMPP.


How to set up a wildcard virtual host in XAMPP?

To set up a wildcard virtual host in XAMPP, follow these steps:

  1. Open the "httpd-vhosts.conf" file located in the "conf" directory inside the XAMPP installation directory (e.g., C:\xampp\apache\conf\extra\httpd-vhosts.conf).
  2. Add the following configuration to create a wildcard virtual host:
1
2
3
4
5
6
7
<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
    ServerAlias *.localhost
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" common
</VirtualHost>


This configuration sets up a wildcard virtual host that will serve all subdomains of "localhost" from the same document root directory.

  1. Save the changes to the file.
  2. Open the "hosts" file located in the "etc" directory inside the Windows\System32\drivers directory (e.g., C:\Windows\System32\drivers\etc\hosts) with a text editor.
  3. Add the following line to map all subdomains to localhost:
1
127.0.0.1 localhost


  1. Save the "hosts" file.
  2. Restart the Apache server in the XAMPP control panel.
  3. Now you should be able to access any subdomain of "localhost" in your browser and it will point to the same document root directory specified in the virtual host configuration.


That's it! You have successfully set up a wildcard virtual host in XAMPP.

Facebook Twitter LinkedIn Telegram

Related Posts:

To avoid using sudo in XAMPP, you can change the ownership of the XAMPP folder to the current user. This will allow you to run XAMPP commands without sudo. To do this, navigate to the XAMPP installation directory and run the following command: sudo chown -R $U...
To change the root folder in XAMPP, you need to navigate to the httpd.conf file in the XAMPP installation folder. Look for the DocumentRoot directive in this file and change the path to the desired root folder. Save the changes and restart the Apache server in...
To enable the mcrypt PHP extension on XAMPP on Linux, you first need to navigate to the PHP configuration folder. This is typically located at /opt/lampp/etc/php. Once in the folder, open the php.ini file in a text editor.Search for the line extension=mcrypt.s...
To change the max_connections_per_hour in XAMPP, you need to edit the MySQL configuration file.Locate the my.cnf or my.ini file in the XAMPP installation directory.Open the file in a text editor.Search for the [mysqld] section in the file.Add the following lin...
To install PHP 8 on XAMPP, you will need to download the latest version of PHP 8 from the official PHP website. Once you have downloaded the PHP 8 files, you will need to extract them to a directory on your computer.Next, navigate to the XAMPP installation dir...