Home >Backend Development >PHP Tutorial >PHP realizes the binding of an IP (such as: 127.0.0.1) and multiple domain names (virtual hosts), 127.0.0.1 virtual host_PHP tutorial
Solution 1: Through the port Distinguish between different virtual hosts
①Be prepared according to the method of binding a site
1. Develop your own website first (d:/myblog (stored in the myblog directory of D drive))
2. Configure the httpd.conf file (stored in the conf folder of the apache installation directory) and enable httpd-vhosts.conf (just remove the # sign in front of the second line).
3. Configure the httpd-vhosts.conf file (stored in the extra folder of the apache installation directory)
4. Add the corresponding relationship between IP and domain name in the hosts file
C:/Windows/System32/drivers/etc/hosts
5. It is recommended to log out of DocumentRoot (document root directory) in the httpd.conf file
6. Test, enter "http://www.shunping1.com" in the browser to see the homepage of the site
②Add a new domain name to bind to the IP:
1. Develop a new website: d:/myblog2
2. Configure the httpd.conf file (stored in the conf folder of the apache installation directory) and add a new virtual host
3. Always ask apache to listen to port 81 in the httpd.conf file
4. Add a new domain name in the hosts file
5. To test, enter "http://www.shunping3.com:80" in the browser (the port name must be added)
Solution 2: Distinguish different domain names through ServerName
1. Develop a new site d:/myblog2
2. Instruct apache to cancel monitoring port 81 in the httpd.conf file (add # in front or delete it directly)
3. Add configuration in the httpd-vhosts.conf file (note that the configuration here is different from the one in Solution 1)
4. Other configurations remain unchanged