Configure multiple websites in XAMPP

WBOY
Release: 2016-08-08 09:20:43
Original
860 people have browsed it

XAMPP virtual host configuration, multiple domain name bindings to access local sites
XAMPP Sometimes you need some top-level domain name access methods to access your local projects, that is, virtual host configuration. At this time, you need to configure the virtual host and bind it to your directory Define a domain name to achieve binding access to multiple domain names.

I have always used MAMP to build a local php environment on Mac because of its powerful combination configuration and convenient UI operations. Because the company's computers are Windows, sometimes you need to set up a PHP environment to debug some small things to facilitate your work. Since it is just a small application, there is no need to build a local WAMP environment by yourself. There are still many WAMP environment integration packages online. I have never used PHPNow, WampServer, PHPStudy, AppServ, EasyPHP, etc., and UniServer, which I have been using before, is so dazzling that I am dazzled. I actually don’t know the reason why I didn’t use UniServer later. UniServer is very powerful and worth recommending, but then I switched to XAMPP because it is also very powerful and the file package is more than 100MB. Of course, you can download the Lite version. , but the file size was several times larger than that of UniServer. Maybe it was because of its size that I later switched to XAMPP.
Sometimes you need some top-level domain name access methods to access your local project files instead of directory access. At this time, you need to configure a virtual host and bind a domain name to your directory (locally, you can modify the hosts file as you like. What domain name to bind (such as www.a.com or localdemo).
Now assume you have two directories, one exists in /xampp/htdocs/a and the other exists in /xampp/htdocs/b .
Now when you want to test locally, the corresponding directory for accessing www.a.com is /xampp/htdocs/a, and the corresponding directory for accessing www.b.com is /xampp/htdocs/b.
You can actually bypass it if you know how to configure Apache, because XAMPP is nothing more than integrating environment integration packages such as APache, and implementing multiple domain names is achieved by configuring Apache.
Of course, there are many methods that can be found online, but the information on the Internet is reprinted and reprinted. I doubt whether some methods have been verified or not and I don’t know whether they are correct. The following method was personally tested by me. If you still cannot achieve local multi-domain debugging according to my configuration, it may be because your XAMPP version is inconsistent with mine. You can tell me in the comments below and I will answer it for you. The following configuration is for XAMPP Windows 1.7.1 version.
1. First modify the hosts file in the WINDOWSsystem32driversetc directory on drive C, open it with Notepad, and add:

(added at the end of the file)
127.0.0.1 www.a.com
127.0.0.1 www.b.com
2. Open the xamppapacheconfhttpd.conf file and search for "Include conf/extra /httpd-vhosts.conf", make sure there is no # comment in front, that is, make sure the vhosts virtual host configuration file is introduced.
After httpd-vhosts.conf is enabled, the default httpd.conf default configuration becomes invalid (make sure the virtual host configuration is also enabled in the httpd-vhosts.conf file, see Article 3), and all domain names accessing this IP will point to vhosts The first virtual host in .conf. (Note that it is the first one, see Chapter 4 for details)
3. Set in the virtual host setting file xamppapacheconfextrahttpd-vhosts.conf:
Cancel the ## in front of NameVirtualHost *:80, thus enabling vhosts.conf , the default httpd.conf default configuration is invalid. Virtual host configuration will only be set in httpd-vhosts.conf.

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


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

4. After setting item 3, you will find that accessing localhost directly points to the path set to a Yes, this issue is discussed in Article 2. That is to say, after vhosts is enabled, the default httpd configuration will become invalid, and the default access will point to the first setting in vhosts. At this time, you need to set back the localhost directory configuration.

DocumentRoot /xampp/htdocs/
ServerName localhost

Now, the virtual host of XAMPP is set up , now accessing localhost is still the same as before XAMPP help guide, accessing www.a.com will point to the bound a directory, accessing www.b.com will point to the bound b directory.
-------------------------------------------------- ----------------------------------
Instance reference:
XAMPP adds VirtualHost to support multiple sites
Add the following content in the c:xamppapacheconfextrahttpd-vhosts.conf file:
NameVirtualHost *:80

DocumentRoot "E:/php/wordpress"
ServerName wordpress

(This paragraph must be added, otherwise it will not be accessible)

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

DocumentRoot "D:/xampp/htdocs/"

ServerName localhost


Add it to the hosts file in the C:WINDOWSsystem32driveversetc directory The following content:
127.0.0.1 wordpress
In the file httpd-vhosts.conf:
#NameVirtualHost *:80
Just remove the #
The above introduces the configuration of multiple websites in XAMPP, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template