Table of Contents
【转】XAMPP中配置多个网站,xampp配置多个
Home php教程 php手册 【转】XAMPP中配置多个网站,xampp配置多个

【转】XAMPP中配置多个网站,xampp配置多个

Jun 13, 2016 am 08:57 AM
xampp Multiple website virtual change Configuration

【转】XAMPP中配置多个网站,xampp配置多个

XAMPP虚拟主机配置,多域名绑定访问本地站点

XAMPP有时候你需要一些顶级域名访问方式来访问你本地的项目也就是虚拟主机配置,这时候就需要配置虚拟主机,给你的目录绑定一个域名,实现多域名绑定访问。


在Mac 下一直使用 MAMP 搭建本地 php 环境,因为其强大的组合配置以及方便的 UI 操作。因为公司的电脑是 Windows的,有时候需要搭建 php 环境来调试一些小东西方便自己工作,因为只是小应用,所以自己搭建本地的 WAMP 环境就没有必要了,网上的 WAMP环境集成包还是很多的,什么 PHPNow 啊,WampServer 啊,PHPStudy 啊,AppServ 啊,EasyPHP啊之类的我都没用过,以及我之前一直在使用的 UniServer,琳琅满目啊,看得我眼花缭乱。之所以后来不用 UniServer的原因其实我也不知道, UniServer 很强大,值得推荐一下,但是后来我又转用了 XAMPP ,因为它也很强大,并且文件包达 100MB还多,当然你可以下载 Lite 版本,但是文件大小都比 UniServer 大出好几倍,可能就是因为它的大,后来我才转用了 XAMPP。

有时候你需要一些顶级域名访问方式来访问你本地的项目文件而不是目录方式访问,这时候就需要配置虚拟主机,给你的目录绑定一个域名(本地的话可以通过修改 hosts 文件随便绑定什么域名比如 www.a.com 或者 localdemo)。
现在假定你有两个目录,一个存在于 /xampp/htdocs/a,另一个存在于 /xampp/htdocs/b 。
现在你想要在本地测试的时候访问 www.a.com 对应的目录是 /xampp/htdocs/a ,访问 www.b.com 对应的目录是 /xampp/htdocs/b 。
懂得 Apache配置的其实就可以绕开了,因为 XAMPP 无非就是集成了 APache 之类的环境集成包,实现多域名也就是通过配置 Apache 实现的。

当 然网上搜索到的方法很多,但是网上的信息都是转载来转载去的,有的方法我怀疑是否验证过是否正确都不知道。以下的方法是我亲测的,如果你按照我的配置还是 无法实现本地多域名调试的话,可能是因为你的 XAMPP 的版本和我的不一致造成的。你可以在下面评论告知我,我会给你一一解答。以下配置针对的是XAMPP Windows 1.7.1 版本。

1、首先修改C盘WINDOWS\system32\drivers\etc目录下的 hosts 文件,用记事本打开,加入:

(是在文件的未尾加入)
127.0.0.1 www.a.com
127.0.0.1 www.b.com

2、打开xampp\apache\conf\httpd.conf文件,搜索 “Include conf/extra/httpd-vhosts.conf”,确保前面没有 # 注释符,也就是确保引入了 vhosts 虚拟主机配置文件。

开启了httpd-vhosts.conf,默认的httpd.conf默认配置失效(确保 httpd-vhosts.conf 文件里也开启了虚拟主机配置,见第3条),访问此IP的域名将全部指向 vhosts.conf 中的第一个虚拟主机。(注意是第一个,详见第4)

3、在虚拟主机设置文件xampp\apache\conf\extra\httpd-vhosts.conf里设置:
取消 NameVirtualHost *:80 前面的 ##,这样就启用了 vhosts.conf ,默认的httpd.conf默认配置失效。虚拟主机配置将只设置在 httpd-vhosts.conf 里。

DocumentRoot /xampp/htdocs/a
ServerName www.a.com



DocumentRoot /xampp/htdocs/b
ServerName www.b.com


4、 设置完了第3条之后,你会发现访问 localhost直接指向到设置的 a 那个路径去了,这个问题在第2条有讲。也就是开启了 vhosts后,默认的 httpd 的配置就会失效了,默认的访问就指向到 vhosts 里的第一条设置去了。这时候你要把 localhost的目录配置给设置回来。

DocumentRoot /xampp/htdocs/
ServerName localhost


至此,XAMPP 的虚拟主机设置完毕,现在 访问 localhost 还是原来的 XAMPP 的帮助指南,访问 www.a.com 将指向到绑定的 a 目录,访问 www.b.com 将指向到绑定的 b 目录。

--------------------------------------------------------------------------------

实例参考:
XAMPP添加VirtualHost以支持多个站点
在c:\xampp\apache\conf\extra\httpd-vhosts.conf文件中添加如下内容:

NameVirtualHost *:80


DocumentRoot "E:/php/wordpress"
ServerName wordpress

(这一段必须加入,不然无法访问)

Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all

 

(这一段将localhost默认访问设置回来,将必须放在后面)

DocumentRoot "D:/xampp/htdocs/"
ServerName localhost


在C:\WINDOWS\system32\drivers\etc目录下的hosts文件中添加如下内容:

127.0.0.1 wordpress

把文件httpd-vhosts.conf里: 
#NameVirtualHost *:80 

把去掉#就好了

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The working principle and configuration method of GDM in Linux system The working principle and configuration method of GDM in Linux system Mar 01, 2024 pm 06:36 PM

Title: The working principle and configuration method of GDM in Linux systems In Linux operating systems, GDM (GNOMEDisplayManager) is a common display manager used to control graphical user interface (GUI) login and user session management. This article will introduce the working principle and configuration method of GDM, as well as provide specific code examples. 1. Working principle of GDM GDM is the display manager in the GNOME desktop environment. It is responsible for starting the X server and providing the login interface. The user enters

Understand Linux Bashrc: functions, configuration and usage Understand Linux Bashrc: functions, configuration and usage Mar 20, 2024 pm 03:30 PM

Understanding Linux Bashrc: Function, Configuration and Usage In Linux systems, Bashrc (BourneAgainShellruncommands) is a very important configuration file, which contains various commands and settings that are automatically run when the system starts. The Bashrc file is usually located in the user's home directory and is a hidden file. Its function is to customize the Bashshell environment for the user. 1. Bashrc function setting environment

How to configure and install FTPS in Linux system How to configure and install FTPS in Linux system Mar 20, 2024 pm 02:03 PM

Title: How to configure and install FTPS in Linux system, specific code examples are required. In Linux system, FTPS is a secure file transfer protocol. Compared with FTP, FTPS encrypts the transmitted data through TLS/SSL protocol, which improves Security of data transmission. In this article, we will introduce how to configure and install FTPS in a Linux system and provide specific code examples. Step 1: Install vsftpd Open the terminal and enter the following command to install vsftpd: sudo

Where can I check the configuration of my win11 computer? How to find the configuration information of win11 computer Where can I check the configuration of my win11 computer? How to find the configuration information of win11 computer Mar 06, 2024 am 10:10 AM

When we use win11 system, we sometimes need to check the configuration of our computer, but many users are also asking where to check the configuration of win11 computer? In fact, the method is very simple. Users can directly open the system information under settings, and then view the computer configuration information. Let this site carefully introduce to users how to find win11 computer configuration information. How to find win11 computer configuration information. Method 1: 1. Click Start and open Computer Settings. 3. You can view computer configuration information on this page. 2. In the command prompt window, enter systeminfo and press Enter to view the computer configuration.

XAMPP encountered PHP execution exception? Troubleshooting tips to help XAMPP encountered PHP execution exception? Troubleshooting tips to help Mar 12, 2024 pm 03:21 PM

In the technical field, XAMPP is a commonly used development environment tool. It integrates software such as Apache, MySQL, PHP and Perl, and can help developers quickly build a local server environment. However, sometimes when using XAMPP, you will encounter PHP execution exception problems, which may cause problems in development work. This article will share some troubleshooting techniques to help readers solve the problem when XAMPP encounters PHP execution exceptions. 1. Check the PHP error log. First, when the P in XAMPP

Different types of Linux log files and setting steps Different types of Linux log files and setting steps Feb 26, 2024 pm 10:54 PM

Types of Linux log files and configuration methods In Linux systems, log files are very important. They record the running status of the system, user operations, and the occurrence of various events. By checking log files, system administrators can discover problems in time and handle them accordingly. This article will introduce the common types of log files in Linux systems and how to configure logging. 1. Types of log files System log: System log is a log file that records the operating status of the system, including system startup, shutdown, service startup and stop, etc.

Computer configuration recommendations for building a high-performance Python programming workstation Computer configuration recommendations for building a high-performance Python programming workstation Mar 25, 2024 pm 07:12 PM

Title: Computer configuration recommendations for building a high-performance Python programming workstation. With the widespread application of the Python language in data analysis, artificial intelligence and other fields, more and more developers and researchers have an increasing demand for building high-performance Python programming workstations. When choosing a computer configuration, in addition to performance considerations, it should also be optimized according to the characteristics of Python programming to improve programming efficiency and running speed. This article will introduce how to build a high-performance Python programming workstation and provide specific

What computer configuration does Black Myth Wukong require? What computer configuration does Black Myth Wukong require? Mar 08, 2024 pm 01:22 PM

The game Black Myth Wukong will be launched on all major platforms in the summer of 2024. Players need to meet certain computer configurations when downloading the game to experience it. The following is an introduction to the minimum configuration required for Black Myth Wukong. What computer configuration is required for Black Myth Wukong? Minimum configuration operating system: Windows 7, Windows 8.1, Windows 10 (all 64-bit) Processor: Intel Corei5-4430/AMDFX-6300 Running memory: 8GB RAM Graphics card: NVIDIA GeForce GTX9602GB/AMDRadeon R73702GB Storage space: 100GB required Available space recommended operating system: Windows 7, Win

See all articles