How to Configure XAMPP Virtual Host in Windows 10

20 January 2021

Home » Blogs » Framework » How to Configure XAMPP Virtual Host in Windows 10

The term refers to the practice of running more than one website (such as example1.com and example2.com) on a single machine. A can be “IP-based”, meaning you have a different IP address for each website, or “name-based”, meaning you have multiple names running on each IP address. The fact that they run on the same physical server is invisible to the end-user.

was one of the first servers to support IP-based virtual hosts. version 1.1 and later support IP-based and name-based virtual hosts (vhosts). The last variant of a is sometimes also called a host-based or non-IP.

Virtual Host Configuration on XAMPP

xampp 2
  1. Open the Virtual Hosts configuration file in the installation directory (for example) in “C:\\apache\conf\extra\httpd-vhosts.conf
  2. Add the following code at the end of the file

    ServerName www.example1.com
    DocumentRoot "C:\XAMPP\htdocs"
   
        Options Indexes FollowSymLinks Includes ExecCGI
        Order allow,deny
        Allow from all
  
  1. Add a setting at the end of a host file in “C:\\System32\\etc\host“.
127.0.0.1  www.example1.com

Virtual Configuration hosts multiple domains with one public IP

  1. For example, we have 2 domains with www.example1.com and www.example2.com names.
  2. Add the following code at the end of the httpd-vhosts.conf file

    ServerName www.example1.com
    DocumentRoot "C:\XAMPP\htdocs\www.example1.com"
   
        Options Indexes FollowSymLinks Includes ExecCGI
        Order allow,deny
        Allow from all
  
 

    ServerName www.example2.com
    DocumentRoot "C:\XAMPP\htdocs\www.example2.com"
   
        Options Indexes FollowSymLinks Includes ExecCGI
        Order allow,deny
        Allow from all
  
  1. Add a setting at the end of a host file in “C:\\System32\drivers\etc\host”.
127.0.0.1  www.example1.com
127.0.0.1  www.example2.com

Virtual Configuration Of Multiple Domain and IP Hosts

  1. For example we have 2 domains with www.example1.com names, ip 172.20.30.40 and www.example2.com, ip 172.20.30.50.
  2. Add the following code at the end of the httpd-vhosts.conf file

    ServerName www.example1.com
    DocumentRoot "C:\XAMPP\htdocs\www.example1.com"
   
        Options Indexes FollowSymLinks Includes ExecCGI
        Order allow,deny
        Allow from all
  
 

    ServerName www.example2.com
    DocumentRoot "C:\XAMPP\htdocs\www.example2.com"
   
        Options Indexes FollowSymLinks Includes ExecCGI
        Order allow,deny
        Allow from all
  
  1. Add a setting at the end of a windows host file in “C:\Windows\System32\drivers\etc\host”.
127.0.0.1 www.example1.com
127.0.0.1 www.example2.com

Virtual Host Configuration with Different Ports

  1. For example we have 2 domains with www.example1.com names, ip 172.20.30.40 and www.example2.com, ip 172.20.30.50 running on port 80 and www.example3com, ip 172.20.30.50 with port 8080.
  2. Add the following code at the end of the httpd-vhosts.conf file

    ServerName www.example1.com
    DocumentRoot "C:\XAMPP\htdocs\www.example1.com"
   
        Options Indexes FollowSymLinks Includes ExecCGI
        Order allow,deny
        Allow from all
  
 

    ServerName www.example2.com
    DocumentRoot "C:\XAMPP\htdocs\www.example2.com"
   
        Options Indexes FollowSymLinks Includes ExecCGI
        Order allow,deny
        Allow from all
  
 

    ServerName www.example3.com
    DocumentRoot "C:\XAMPP\htdocs\www.example3.com"
   
        Options Indexes FollowSymLinks Includes ExecCGI
        Order allow,deny
        Allow from all
  
  1. Add a setting at the end of a windows host file in “C:\Windows\System32\drivers\etc\host”.
127.0.0.1 www.example1.com
127.0.0.1 www.example2.com
127.0.0.1 www.example3.com

Configure Virtual Host with SSL

  1. Create an SSL Certificate, discussed in the next article.
    For example a certificate with the file name “server.crt“, “server.key
  2. Place the on C:\XAMPPapacheconf
  3. Add the following code at the end of the httpd-vhosts.conf file

    ServerName www.example1.com
    DocumentRoot "C:\XAMPP\htdocs\www.example1.com"
    SSLEngine on
    SSLCertificateFile "conf/ssl.crt/server.crt"
    SSLCertificateKeyFile "conf/ssl.key/server.key"
   
        Options Indexes FollowSymLinks Includes ExecCGI
        Order allow,deny
        Allow from all
  

TOP TUTORIALS:  How to Remotely Disable Windows Firewall

0 Comments