This article mainly shares with you how to configure domain name access locally in phpstudy. I hope it can help you.
1. Hosts configuration:
1. Open the hosts file with an editor, location: C:\Windows\System32\drivers\etc directory
Example:
Add the following code at the end of the hosts file:
127.0.0.1 www.tp5.com
2. apache configuration:
1 .Edit the httpd.conf file and enable the virtual host. Location: In the apache installation directory, that is, phpStudy\Apache\conf under the phpstudy installation directory, find Includeconf/extra/httpd-vhosts.conf and remove the preceding
#2. Enter the opened virtual host file httpd-vhosts.conf to configure the domain name. Location: \phpStudy\Apache\conf\extra directory
Configuration rules:
ServerAdminwebmaster@dummy-host.example.com DocumentRoot"D:/phpStudy/WWW/要配置域名的项目名" ServerName 配置的域名 ErrorLog"logs/dummy-host2.example.com-error.log" CustomLog"logs/dummy-host2.example.com-access.log" common
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 can also be achieved through domain name configuration, as follows:
DocumentRoot"D:/phpStudy/WWW/h5.test.cn" ServerNamelocal.h5.test.cn DirectoryIndexindex.php
After the above configuration is completed, remember to restart the server.
Note: A problem arises at this time, that is, if you use localhost to access other local projects, you cannot access them. With so many projects, I don’t want to configure a virtual domain name for each one. It can be accessed by both domain name and localhost. I found a solution on the Internet:
Use the above method to add a domain name named localhost and bind it to the www directory, then comment out the ServerName localhost line in the httpd.conf file, restart apache, and then All can be accessed.
Related recommendations:
How to configure the domain name in wampserver
Record the process of lampp configuring the domain name directory.
Linux configuration domain name solution
The above is the detailed content of How to configure domain name access locally in phpstudy (illustrated steps). For more information, please follow other related articles on the PHP Chinese website!