How To Fix PHP Errors Not Being Logged
I recently spent a lot of time trying to understand why PHP errors were not being logged on a newly invoked Centos Web Panel installation. HTTP 500 errors with nothing shown in the log makes it very difficult to debug the problem.
In my investigations I found a number of potential reasons why this might be the case, so I have summarised them all here
1. Make Sure You’re Editing The Correct php.ini File
With the latest version of Centos Web Panel, you can have multiple versions of PHP installed on the server. Check which version you are using with phpinfo(). It shows the path to the php.ini file. Look for ‘Loaded Configuration File’
2. Edit php.ini
There are a number of PHP directives that need to be set to ensure errors are logged. I am used to the errors being reported in the Apache log, so that’s where I am going to send them.
Edit the php.ini file indicated in your phpinfo() page (see above) and make sure the following directives are set how you want (sadly, they don’t all appear together in the file – you will need to find the appropriate lines yourself):
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
log_errors = On
log_errors_max_len = 1024
error_log = /usr/local/apache/logs/error_log
Save the file, then restart Apache.
3. Update Error Log File Permissions
If php errors are still not being logged (I test this by using a php file with a deliberate syntax error), then check the file permissions on the error log file. I found that by changing the permissions from 644 to 646 the errors started appearing in the Apache error log. It seems that errors get reported at the user level and as the Apache error log is owned by root, you must allow write permission to the ‘Other’ group.
How do I see logs?
Login using ssh or download a log file
/var/log/php-scripts.log using sftp client:
# tail -f /var/log/php-scripts.log
We have learned in this tutorial How To Fix PHP Errors Not Being Logged