Home  >  Article  >  Backend Development  >  How to close php error in htaccess

How to close php error in htaccess

藏色散人
藏色散人Original
2021-07-10 10:22:091894browse

htaccess method to turn off php errors: first find the ".htaccess" file; then put the "php_flag display_startup_errors off" and other codes into the ".htaccess" file in the corresponding directory.

How to close php error in htaccess

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How to close php error in htaccess?

Use .htaccess to turn off PHP error display

Put the following corresponding code into the .htaccess file in the corresponding directory to achieve the corresponding function.

Turn off error display:

php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_value docref_root 0
php_value docref_ext 0

Only display PHP errors:

php_flag  display_errors        on
php_flag  display_startup_errors on
php_value error_reporting        2047

Among them, "2047" is the level of the error to be displayed. The detailed table is as follows:

1 E_ERROR
2 E_WARNING
4 E_PARSE
8 E_NOTICE
16 E_CORE_ERROR
32 E_CORE_WARNING
64 E_COMPILE_ERROR
128 E_COMPILE_WARNING
256 E_USER_ERROR
512 E_USER_WARNING
1024 E_USER_NOTICE
2047 E_ALL
2048 E_STRICT
4096 E_RECOVERABLE_ERROR

To save errors to a log file, you can set it like this:

# enable PHP error logging
php_flag  log_errors on
php_value error_log  /home/path/public_html/domain/PHP_errors.log

Then, you can set not to allow access to the .log file:

# prevent access to PHP error log
Order allow,deny
Deny from all
Satisfy All

Set the maximum size of the error log, in bytes Unit:

# general directive for setting max error size
log_errors_max_len integer

Based on the above, summary of PHP error display settings for .htaccess:

# PHP error handling for production servers
# disable display of startup errors
php_flag display_startup_errors off
# disable display of all other errors
php_flag display_errors off
# disable html markup of errors
php_flag html_errors off
# enable logging of errors
php_flag log_errors on
# disable ignoring of repeat errors
php_flag ignore_repeated_errors off
# disable ignoring of unique source errors
php_flag ignore_repeated_source off
# enable logging of php memory leaks
php_flag report_memleaks on
# preserve most recent error via php_errormsg
php_flag track_errors on
# disable formatting of error reference links
php_value docref_root 0
# disable formatting of error reference links
php_value docref_ext 0
# specify path to php error log
php_value error_log /home/path/public_html/domain/PHP_errors.log
# specify recording of all php errors
php_value error_reporting 999999999
# disable max error string length
php_value log_errors_max_len 0
# protect error log by preventing public access
Order allow,deny
Deny from all
Satisfy All

The following are settings suitable for developer applications:

# PHP error handling for development servers
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
php_flag log_errors on
php_flag ignore_repeated_errors off
php_flag ignore_repeated_source off
php_flag report_memleaks on
php_flag track_errors on
php_value docref_root 0
php_value docref_ext 0
php_value error_log /home/path/public_html/domain/PHP_errors.log
php_value error_reporting 999999999
php_value log_errors_max_len 0
Order allow,deny
Deny from all
Satisfy All

Recommended learning: " PHP video tutorial

The above is the detailed content of How to close php error in htaccess. 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