使用.htaccess能夠在某種程度上更改PHP的錯誤顯示的設置,實際上,至關於更改PHP.ini的參數,非常方便。php
將如下相應代碼放到對應目錄中的.htaccess文件,便可實現相應功能。html
關閉錯誤顯示 :dom
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
只顯示PHP錯誤 :spa
php_flag display_errors on php_flag display_startup_errors on php_value error_reporting 2047
其中,「2047」爲要顯示的錯誤的級別,詳細表格以下:日誌
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
要把錯誤保存到日誌文件中 ,能夠這樣設置:orm
# enable PHP error logging php_flag log_errors on php_value error_log /home/path/public_html/domain/PHP_errors.log
而後,能夠設置不容許訪問.log文件 :server
# prevent access to PHP error log <Files PHP_errors.log> Order allow,deny Deny from all Satisfy All </Files>
設置錯誤日誌的最大致積 ,以bytes爲單位:htm
# general directive for
setting max error size
log_errors_max_len integer
綜合上述,.htaccess的PHP錯誤顯示設置彙總 :ci
# 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 <Files /home/path/public_html/domain/PHP_errors.log> Order allow,deny Deny from all Satisfy All </Files>
如下則是適合開發者應用的設置:開發
# 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 <Files /home/path/public_html/domain/PHP_errors.log> Order allow,deny Deny from all Satisfy All </Files> 總之,經過.htaccess設置顯示PHP錯誤
原文來自於:http://sjolzy.cn/PHP-Htaccess-to-set-PHP-error-display.html