简体   繁体   中英

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

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. The error_log file has 755 permissions and belongs to the same group:owner as all other files in public_html .

But, when I force php errors, no errors are displayed or logged. Errors are logged in /usr/local/apache/logs/error_log . And I've restarted 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.

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.

Finally if none of that works, you could set error-logging in-script with 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

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

init.php

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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