phpstudy builds domain name access locally

This article is reproduced from: https://blog.csdn.net/camillezj/article/details/54694554

Proceed as follows:

1.hosts configuration:

1. Open the hosts file with an editor, location: C:\Windows\System32\drivers\etc directory

2. Add your own domain name configuration in the hosts file. The configuration rules are as follows:

127.0.0.1 Domain 1

127.0.0.1 Domain 2

..........

After the configuration is complete, you can save it. You may need administrator privileges to modify this file.

Two.apache configuration:

1. Edit the httpd.conf file, open the virtual host, location: in the apache installation directory, that is, phpStudy\Apache\conf under the phpstudy installation directory, find Include conf/extra/httpd-vhosts.conf, remove the preceding #

2. Enter the opened virtual host file httpd-vhosts.conf for domain name configuration, location: \phpStudy\Apache\conf\extra directory

Configuration rules:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "D:/phpStudy/WWW/Project name to configure domain name"
  ServerName Configured domain name
    ErrorLog "logs/dummy-host2.example.com-error. log"
    CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>

It mainly configures DocumentRoot and ServerName. ServerAdmin, ErrorLog, and CustomLog can be left unconfigured. If they are not configured, they can be deleted directly or commented out with #. The domain names configured above are all domain names configured in hosts. The examples are as follows:

 

 

The above configuration is the default port 80, and it can also be configured on a different port. In this case, the domain name needs to be followed by a port number. Before configuration, you need to check the occupancy of the port number, and do not configure the port number that is already occupied.

Check the port number occupancy: cmd open the command box and enter the command netstat -ano to view, for details, please refer to: http://jingyan.baidu.com/article/3c48dd34491d47e10be358b8.html

(If port 80 is occupied, other ports can be configured.) Configure different port numbers. In the above configuration, change the port number to an unoccupied port for configuration, and also monitor the httpd.conf file in the phpStudy\Apache\conf directory. Change the information of port 80 to the configured port:

 

If you want to hide the entry file index.php in the Apache configuration, even if the access address: localhost/h5.test.cn/index.php/test/index is simplified to localhost/h5.test.cn/test/index, you can pass The domain name configuration is implemented as follows:

<VirtualHost *:80>
    DocumentRoot "D:/phpStudy/WWW/h5.test.cn"
    ServerName local.h5.test.cn
<IfModule dir_module>
DirectoryIndex index.php
</IfModule>
</VirtualHost>

 

After the above configuration is completed, remember to restart the server.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325222957&siteId=291194637
Recommended