In PHP website development, to ensure the security of website directory files and program code, we must control the access permissions of some directories or files to improve website security, how can we implement this function? In this case, you can configure Apache to prohibit websites from listing website content in the form of directories.
When directory access is not configured in Apache, related directories and file lists are listed when you access http: // localhost. You can modify the Apache configuration file httpd. conf to disable the list of directories/FILES. The method is as follows:
1. Open the apache configuration file "httpd. conf"
2. Find the following parts:
The code is as follows: |
Copy code |
<Directory/> Options Indexes AllowOverride None Order allow, deny Allow from all </Directory> |
You only need to change Options Indexes to Options None.
Note: depending on the installation package of the PHP running environment, Options Indexes may also be Options Indexes FollowSymLinks, which can be changed to Options None.
Save httpd. conf and restart apache. If not, modify the following configuration:
The code is as follows: |
Copy code |
<Directory "E:/web">
# # Possible values for the Options directive are "None", "All ", # Or any combination: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named * explicitly * --- "Options All" # Doesn' t give it to you. # # The Options directive is both complicated and important. Please see # Http://httpd.apache.org/docs/2.2/mod/core.html#options # For more information. # Options none # # AllowOverride controls what directives may be placed in. htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None # # Controls who can get stuff from this server. # Order allow, deny Allow from all </Directory> |
As above: just change the red part.
3. Save httpd. conf, restart Apache, and then access http: // localhost. If no index.html or index exists. when the default files such as php are used, the following error message is returned:
Forbidden
You don't have permission to access/on this server.