仅通过 htaccess 在 PHP 中启用错误显示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6127980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Enabling error display in PHP via htaccess only
提问by Ogugua Belonwu
I am testing a website online.
我正在在线测试一个网站。
Right now, the errors are not being displayed (but I know they exist).
现在,没有显示错误(但我知道它们存在)。
I have access to only the .htaccess
file.
我只能访问该.htaccess
文件。
How do I make all errors to display using my .htaccess
file?
如何使用我的.htaccess
文件显示所有错误?
I added these lines to my .htaccess
file:
我将这些行添加到我的.htaccess
文件中:
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
And the pages nowdisplay:
现在页面显示:
Internal server error
内部服务器错误
回答by silex
.htaccess:
.htaccess:
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
php_flag log_errors on
php_value error_log /home/path/public_html/domain/PHP_errors.log
回答by UFTimmy
php_flag display_errors on
To turn the actual display of errors on.
打开错误的实际显示。
To set the types of errors you are displaying, you will need to use:
要设置您显示的错误类型,您需要使用:
php_value error_reporting <integer>
Combined with the integer values from this page: http://php.net/manual/en/errorfunc.constants.php
结合本页的整数值:http: //php.net/manual/en/errorfunc.constants.php
Note if you use -1 for your integer, it will show all errors, and be future proof when they add in new types of errors.
请注意,如果您对整数使用 -1,它将显示所有错误,并在他们添加新类型的错误时成为未来证明。
回答by Ashish
I feel like adding more details to the existing answer:
我想在现有答案中添加更多细节:
# 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 /full/path/to/file/php_errors.log
php_value error_reporting -1
php_value log_errors_max_len 0
Give 777 or 755 permission to the log file and then add the code
给日志文件777或755权限,然后添加代码
<Files php_errors.log>
Order allow,deny
Deny from all
Satisfy All
</Files>
at the end of .htaccess. This will protect your log file.
在 .htaccess 的末尾。这将保护您的日志文件。
These options are suited for a development server. For a production server you should not display any error to the end user. So change the display flags to off.
这些选项适用于开发服务器。对于生产服务器,您不应向最终用户显示任何错误。因此,将显示标志更改为off。
For more information, follow this link: Advanced PHP Error Handling via htaccess
有关更多信息,请访问此链接:通过 htaccess 进行高级 PHP 错误处理
回答by Zeke
If you want to see only fatal runtime errors:
如果您只想查看致命的运行时错误:
php_value display_errors on
php_value error_reporting 4
回答by Darkcoder
This works for me (reference):
这对我有用(参考):
# 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
# [see footnote 3] # php_value error_reporting 999999999
php_value error_reporting -1
# Disable max error string length
php_value log_errors_max_len 0
# Protect error log by preventing public access
<Files PHP_errors.log>
Order allow,deny
Deny from all
Satisfy All
</Files>