PHP error_log method doesn’t write errors to the error log file

apacheloggingPHP

The PHP error_log method does not write errors to the custom error log file. It will only write to /var/log/apache2/php_error.log

Here are the logging settings in my php.ini:

error_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE
display_errors = Off
log_errors = On
log_errors_max_len = 0 ; also tried with 9999999
error_log = /var/log/apache2/php_errors.log

PHP writes its errors to the regular Apache error log (/var/log/apache2/error.log) rather than the one I specified above.

Things I already tried:

  1. I stopped and restarted apache after changing the php.ini file
  2. The file /var/log/apache2/php_errors.log is 777 permissions and the file exists.
  3. There are no other overriding php.ini files. (There is /etc/php5/cli/php.ini but I'm not using cli).
  4. There are no other error_log = xxx settings further down the php.ini file which could overrule the first one
  5. phpinfo() says error_log = /var/log/apache2/php_errors.log (i.e. the correct file), both under Local Value and Master Value
  6. The test script I'm using to generate errors doesn't contain any ini_set calls

(FYI: I'm using Apache/2.2.17 and PHP/5.3.5-1ubuntu7.2 on Ubuntu 11.04)

What am I doing wrong?

Best Answer

I'd like to answer this as it's a high result on Google even though it's an old question.

I solved this by adding write permissions for all users on the log directory.

In my case, the user 'http' needed to be able to write to /var/log/httpd/ so I ran

# chmod a+w /var/log/httpd

If the file already exists, it may help to delete it first and allow Apache to create it.

My php.ini file included the entire path, also.

error_log = /var/log/httpd/php_errors.log
Related Topic