How to Create Virtual Hosts in XAMPP to Run Multiple Websites Locally?

Mary-Kate Olsen
Release: 2024-10-27 09:28:30
Original
261 people have browsed it

How to Create Virtual Hosts in XAMPP to Run Multiple Websites Locally?

How to Create Virtual Hosts in XAMPP

Introduction

XAMPP is a versatile web development stack that allows developers to run a local web server with various services, including Apache, MySQL, and PHP. When running XAMPP on a Windows machine, port 80 may be occupied by a system process. To use XAMPP with a different port, you can create virtual hosts.

Step 1: Configure Virtual Host in httpd-vhosts.conf

Open the httpd-vhosts.conf file located in the XAMPP directory (C:/xampp/apache/config/extra/httpd-vhosts.conf or C:/xampp/apache/conf/extra/httpd-vhosts.conf in newer versions). Add the following code to create a virtual host for your desired website:

<VirtualHost *:80>
    ServerName www.example.com
    DocumentRoot "C:\xampp\htdocs\example"
    SetEnv APPLICATION_ENV "development"
    <Directory "C:\xampp\htdocs\example">
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
Copy after login

Replace "www.example.com" with your desired subdomain and "C:xampphtdocsexample" with the path to your website's root directory.

Step 2: Update Hosts File

Add the following entry to your hosts file (C:WINDOWSsystem32driversetchosts):

127.0.0.1 www.example.com
Copy after login

This maps the subdomain to the local machine's IP address.

Step 3: Enable Virtual Hosts in httpd.conf

Open the httpd.conf file (C:xamppapacheconfhttpd.conf) and locate the following section:

#Virtual hosts
Include conf/extra/httpd-vhosts.conf
Copy after login

Remove the comment by deleting the "#" at the beginning of the second line.

Step 4: Restart Apache Server

Restart the Apache server from within the XAMPP control panel. Once Apache has restarted, you should be able to access your website by typing "www.example.com" into your browser's address bar.

The above is the detailed content of How to Create Virtual Hosts in XAMPP to Run Multiple Websites Locally?. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!