Creating virtual hosts in XAMPP allows you to use multiple websites or domains on your local server. Here's a detailed guide on how to configure virtual hosts in XAMPP:
Step 1: Edit the Hosts File
Open the hosts file located at C:WINDOWSsystem32driversetc and add the following lines:
127.0.0.1 localhost 127.0.0.1 test.example.com 127.0.0.1 example.com
This maps test.example.com and example.com to the local IP address.
Step 2: Configure Virtual Hosts in httpd-vhosts.conf
Navigate to xamppapacheconfextrahttpd-vhosts.conf and add the following virtual host definitions:
<VirtualHost *:80> DocumentRoot "C:/xampp/htdocs/test/" ServerName www.test.example.com </VirtualHost> <VirtualHost *:80> DocumentRoot "C:/xampp/htdocs/example/" ServerName www.example.com </VirtualHost>
The DocumentRoot specifies the directory for each website.
Step 3: Uncomment the Virtual Hosts Configuration in httpd.conf
Open xamppapacheconfhttpd.conf, find the section labeled "Supplemental configuration," and uncomment the following line:
Include conf/extra/httpd-vhosts.conf
Step 4: Restart Apache and Test Virtual Hosts
Restart XAMPP, and access your virtual hosts in the browser by visiting www.example.com and www.test.example.com.
The above is the detailed content of How to Set Up Virtual Hosts in XAMPP for Multiple Websites?. For more information, please follow other related articles on the PHP Chinese website!