Home >Operation and Maintenance >phpstudy >How to configure domain name access locally in phpstudy (illustrated steps)

How to configure domain name access locally in phpstudy (illustrated steps)

小云云
小云云Original
2018-03-20 16:17:0019587browse

This article mainly shares with you how to configure domain name access locally in phpstudy. I hope it can help you.

How to configure domain name access locally in phpstudy (illustrated steps)

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

How to configure domain name access locally in phpstudy (illustrated steps)

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

How to configure domain name access locally in phpstudy (illustrated steps)

#2. Enter the opened virtual host file httpd-vhosts.conf to configure the domain name. Location: \phpStudy\Apache\conf\extra directory

Configuration rules:

<VirtualHost *:80>    
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
</VirtualHost>

How to configure domain name access locally in phpstudy (illustrated steps)

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:

<VirtualHost *:80>  
DocumentRoot"D:/phpStudy/WWW/h5.test.cn"   
ServerNamelocal.h5.test.cn
<IfModuledir_module>
DirectoryIndexindex.php
 </IfModule>
</VirtualHost>

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!

Statement:
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