PHP Configuration
2 entries in php.ini dictate the output of errors:
display_errors
error_reporting
在生产环境中,display_errors
通常设置为Off
(这是一件好事,因为在生产站点中显示错误通常是不可取的!)。
However, in development, it should be set to On
, so that errors get displayed. Check!
error_reporting
(as of PHP 5.3) is set by default to E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
(meaning, everything is shown except for notices, strict standards and deprecation notices). When in doubt, set it to E_ALL
to display all the errors. Check!
Whoa whoa! No check! I can t change my php.ini!
真遗憾。通常,共享主机不允许更改他们的php.ini文件,因此,该选项遗憾不可用。但不要担心!我们有其他选项!
Runtime configuration
In the desired script, we can alter the php.ini entries in runtime! Meaning, it ll run when the script runs! Sweet!
error_reporting(E_ALL);
ini_set("display_errors", "On");
这两行代码将产生与上述更改php.ini条目相同的效果!太棒了!
I still get a blank page/500 error!
这意味着脚本甚至没有运行!这通常发生在您有一个语法错误时!
带有语法错误的脚本甚至都无法进入运行时。它会在编译时失败,这意味着它将使用php.ini中的值,如果您没有更改,可能不允许显示错误。
Error logs
In addition, PHP by default logs errors. In shared hosting, it may be in a dedicated folder or on the same folder as the offending script.
如果您可以访问php.ini,则可以在 error_log
项目下找到它。