The default php configuration file is in/usr/local/apache2/conf/php. ini. we need to set php. ini to make your web more secure! (1) enable the php Security mode.
The default php configuration file is in/usr/local/apache2/conf/php. ini. we need to set php. ini to make your web more secure!
(1) enable the php Security mode
The security mode of php is a very important embedded security mechanism that can control some php functions, such as system (),
At the same time, many File operation functions are subject to permission control, and files of some key files are not allowed, such as/etc/passwd,
However, the default php. ini does not enable the security mode. we can enable it: safe_mode = on.
(2) User Group Security
When safe_mode is enabled and safe_mode_gid is disabled, the php script can access the file and
Group users can also access files.
Recommended value: safe_mode_gid = off
If you do not set it, we may not be able to operate the files under the website directory of our server. for example, we need
During file operations.
(3) main directory for executing programs in safe mode
If security mode is enabled, but you want to execute some programs, you can specify the main directory of the program to be executed:
Safe_mode_exec_dir = D:/usr/bin
Generally, you do not need to execute any program. Therefore, we recommend that you do not execute the System program directory, which can point to a directory,
Then copy the program to be executed, for example: safe_mode_exec_dir = D:/tmp/cmd
However, I recommend that you do not execute any program, so you can point to our webpage Directory:
Safe_mode_exec_dir = D:/usr/www
(4) file inclusion in security mode
If you want to include some public files in safe mode, modify the following options:
Safe_mode_include_dir = D:/usr/www/include/
In fact, the files contained in the php script are all written in the program itself, which can be set as needed.
(5) control directories accessible by php scripts
You can use the open_basedir option to control the PHP script to access only the specified directory, so as to avoid PHP script access.
Files that should not be accessed limit the harm of phpshell to a certain extent. we can generally set to only access the website directory:
Open_basedir = D:/usr/www
(6) disable dangerous functions
If the security mode is enabled, the function is not required, but we should consider it for security. For example,
We do not want to execute a php function that includes system () and so on that can execute commands, or can view php information.
Phpinfo () and other functions, we can disable them:
Disable_functions = system, passthru, exec, shell_exec, popen, phpinfo
If you want to disable operations on any files and directories, you can disable many file operations.
Disable_functions = chdir, chroot, dir, getcwd, opendir, readdir, scandir, fopen, unlink, delete, copy, mkdir, rmdir, rename, file, file_get_contents, fputs, fwrite, chgrp, chmod, chown
The above only lists some file processing functions that are not commonly used. you can also combine the preceding command functions with this function,
You can resist most phpshells.
(7) disable PHP version information leakage in the http header
To prevent hackers from obtaining information about the php version on the server, we can disable this information in the http header:
Expose_php = Off
For example, when hackers telnet www.phpddt.com 80, they will not be able to see the PHP information.
(8) disable registration of global variables
Variables submitted in PHP, including those submitted using POST or GET, are automatically registered as global variables and can be directly accessed,
This is very insecure for the server, so we can disable the register global variable option if we cannot register it as a global variable:
Register_globals = Off
Of course, if this is set, a reasonable way should be used to obtain the corresponding variable, such as getting the variable var submitted by GET,
You need to use $ _ GET ['var'] to obtain it. This php programmer should pay attention to it.
(9) enable magic_quotes_gpc to prevent SQL injection.
SQL injection is a very dangerous problem. in small cases, the website background is intruded, while in heavy cases, the entire server is compromised,
So be careful. Php. ini has a setting:
Magic_quotes_gpc = Off
This is disabled by default. if it is enabled, it will automatically convert the SQL query submitted by the user,
For example, convert 'to \' to prevent SQL injection. Therefore, we recommend the following settings:
Magic_quotes_gpc = On
(10) error message control
In general, php prompts an error when it is not connected to the database or in other cases. the common error message will contain the php script when
The preceding path information or the queried SQL statement information is not safe after the information is provided to the hacker. Therefore, it is recommended that the server disable the error prompt:
Display_errors = Off
If you want to display the error information, you must set the display error level. for example, only the warning information is displayed:
Error_reporting = E_WARNING & E_ERROR
Of course, we recommend that you disable the error message.
(11) error log
We recommend that you record the error information after you disable display_errors to find out the reason for running the server:
Log_errors = On
At the same time, you must set the directory where error logs are stored. it is recommended that the logs of the root apache exist together:
Error_log = D:/usr/local/apache2/logs/php_error.log
Note: You must grant write permissions to apache users and groups.