简体   繁体   English

在CentOS 7.3和PHP7中我无法得到php错误来登录到自定义日志

[英]I can't get php errors to log to a custom log in CentOS 7.3 and PHP7

I have in a php.ini in public_html that has 我在public_html的php.ini中有

display_errors = on

error_reporting = E_ALL | E_STRICT

log_errors on
error_log  /home/account/public_html/error.log

phpinfo shows that the php.ini file in public_html is being loaded. phpinfo显示public_html中的php.ini文件正在加载。 The error_log file has 755 permissions and belongs to the same group:owner as all other files in public_html . error_log文件具有755权限,并且与public_html所有其他文件属于同一group:owner。

But, when I force php errors, no errors are displayed or logged. 但是,当我强制执行php错误时,不会显示或记录任何错误。 Errors are logged in /usr/local/apache/logs/error_log . 错误记录在/usr/local/apache/logs/error_log And I've restarted apache. 我已经重新启动了Apache。

Any ideas? 有任何想法吗?

Try changing: 尝试更改:

log_errors on
error_log  /home/account/public_html/error.log

To

log_errors = on
error_log = /home/account/public_html/error.log

Next, near the top of your script, do: 接下来,在脚本顶部附近,执行以下操作:

echo php_ini_loaded_file(); // to make sure that you're editing the right php.ini
echo ini_get('log_errors'); // should be '1'
echo ini_get('error_log');  // should be path from php.ini

If the settings don't match what you set (I assumed you restarted Apache), check the rest of the php.ini as well as Apache VirtualHost configuration for another setting that may be overriding yours. 如果设置与您设置的设置不匹配(我假设您已重新启动Apache),请检查php.ini的其余部分以及Apache VirtualHost配置,以获取可能会覆盖您的其他设置。

When you run phpInfo() , it will sometimes show a list of ini files that get loaded (not just your basic php.ini . One of them could also contain an override. 当您运行phpInfo() ,它有时会显示要加载的ini文件的列表(不仅仅是基本的php.ini 。其中一个还可以包含替代项。

Finally if none of that works, you could set error-logging in-script with ini_set() . 最后,如果这些都不起作用,则可以使用ini_set()设置脚本错误记录。 Just be aware that if that script itself has an error, this setting may not have the chance to take effect so it's best to do it in a script separate from your main, and require it 请注意,如果该脚本本身有错误,则此设置可能没有机会生效,因此最好在与主脚本分开的脚本中进行设置并要求它

main.php main.php

require_once('./init.php);
// ... your regular script

init.php init.php

ini_set('log_errors', '1');
ini_set('error_log', '/path/to/errors.log');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM