21
votes

PHP via CLI successfully logs errors to /var/log/php_errors.log.

But apache + php does not log errors.

[bla@notebook ~]$ apachectl -v
Server version: Apache/2.2.17 (Unix)
Server built:   May 19 2011 03:15:39

[bla@notebook ~]$ php -v
PHP 5.3.6 with Suhosin-Patch (cli) (built: Mar 23 2011 13:28:00) 
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

In php.ini I have:

display_errors = On
error_reporting = E_ALL | E_STRICT
log_errors = On
error_log = php_errors.log

In httpd.conf:

ErrorLog "/var/log/httpd/error_log"

Permissions:

[bla@notebook /]$ ls -la /var/log/httpd/
-rwxrwxr-x 1 root root 133351 21.11.2011 11:18 access_log*
-rwxrwxr-x 1 root http   1307 21.11.2011 11:18 error_log*

[bla@notebook /]$ ls -la /var/log/php_errors.log 
-rwxrwxr-x 1 root http 521 14.11.2011 17:31 /var/log/php_errors.log*

As you can see the Apache daemon has permissions to write into log files.

Still no errors from Apache or PHP in /var/log/php_errors.log and /var/log/httpd/error_log.

UPDATE 1.

Changed this line in php.ini:

error_log = php_errors.log 

to full path:

error_log = /var/log/php_errors.log 

Permissions were ok. But if someone is also having problems with it, you can debug setting permissions to logfile 0777 or changing file owner.

7
Anything to do with php.ini? some of that defaults automatically to working at CLI but has to be enabled when running in a web server.PurplePilot
For example what settings can be missing? Can't find out.Justinas Lelys
In m case it was forgotten config in virtualhost: php_admin_value error_reporting 'E_ALL & ~E_STRICT'.pevik

7 Answers

9
votes

There are usually two separate php.ini files for Apache and CLI - are you sure you're looking at the correct one?

Edit:

2 more options that I can think of:

  • some Apache directive is messing with PHP's log path (or disabling the logging options, though that is very unlikely to be the case) - try setting an absolute path to the log file in php.ini (@Frosty Z has suggested something like this)
  • I notice that your PHP installation has the Suhosin patch applied, which does several restrictive modifications in order to improve security. And while in theory there are sufficient permissions for a user in the http user group to write to the logfile - there's probably some suphp-like behaviour and when your script is accessed through the web it is executed with/as the username that is set as it's owner (file owner of the script that is) - try changing it.
5
votes

I had the same problem.

Setting log_errors_max_len = 0 in php.ini worked for me.

PHP manual:

Set the maximum length of log_errors in bytes. In error_log information about the source is added. The default is 1024 and 0 allows to not apply any maximum length at all. This length is applied to logged errors, displayed errors and also to $php_errormsg, but not to explicitly called functions such as error_log().

2
votes

In the past, I had no error logs in two cases:

  1. The user under which Apache was running had no permissions to modify php_error_log file.
  2. Error 500 occurred because of bad configuration of .htaccess, for example wrong rewrite module settings. In this situation errors are logged to Apache error_log file.
0
votes

Check which PHP script you are accessing, and how Apache is configured in order to access it.

In some configurations (e.g. Virtual hosts, specific directories...), the error_log file can be set to a different path/name than the default one.

I would then suggest to check your Apache config files.

0
votes

httpd.conf is not the only place where Apache config can sit,

For example:

if you use secure connection https:// your extra config will prevail and you would need to look for configuration in files like /opt/local/apache2/conf/extra/httpd-ssl.conf

you can find there something like:

ErrorLog "/var/log/apache/ssl_error.log"

And you will see no errors logged in normal log file, but all of them will go to ssl_error.log

0
votes

This can also be caused by Apache's own LogLevel directive, which if set too high will override PHP's logging. However, it does not override PHP's ability to output errors on the page, ie display_error, and also does not affect CLI PHP. Worth looking into if you have that particular set of symptoms.

0
votes

Checking the logpath on the right server helped for me... facepalm