How to Set Up Virtual Hosts in XAMPP for Multiple Websites?

Susan Sarandon
Release: 2024-10-27 10:18:03
Original
433 people have browsed it

How to Set Up Virtual Hosts in XAMPP for Multiple Websites?

Setting Up Virtual Hosts in XAMPP

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
Copy after login

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>
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template