[CentOS] Redirecting PHP error messages into a log file

Keith Roberts keith at karsites.net
Sat Jul 31 12:48:40 UTC 2010


On Sat, 31 Jul 2010, Alexander Farber wrote:

> To: CentOS mailing list <centos at centos.org>
> From: Alexander Farber <alexander.farber at gmail.com>
> Subject: [CentOS] Redirecting PHP error messages into a log file
> 
> Hello,
>
> I'm using CentOS release 5.5 x86_64 with the stock php-5.1.6-27.el5
> and would like to redirect PHP messages into /var/log/httpd/php_log
>
> First I tried adding that file name to /etc/php.ini:
> error_log = "/var/log/httpd/php_log"
> and restarted httpd, but the file didn't appear.
> I've touched it and changed owner to apache.apache,
> but that didn't help.

It's a bit tricky setting up PHP error logging to a seperate 
file. This works for me on 32bit, Centos 5.5 and Fedora 12, 
and previous Fedora versions.

Here are my settings:

SELinux disabled at boot time.

/etc/php.ini file:

; Besides displaying errors, PHP can also log errors to locations such as a 
; server-specific log, STDERR, or a location specified by the error_log
; directive found below. While errors should not be displayed on productions
; servers they should still be monitored and logging is a great way to do that.
; Default Value: Off
; Development Value: On
; Production Value: On
; 
http://www.php.net/manual/en/errorfunc.configuration.php#ini.log-errors
log_errors = ON


; Set maximum length of log_errors. In error_log information about the source is
; added. The default is 1024 and 0 allows to not apply any maximum length at all.
; http://www.php.net/manual/en/errorfunc.configuration.php#ini.log-errors-max-len
log_errors_max_len = 1024

; Do not log repeated messages. Repeated errors must occur in same file on same
; line unless ignore_repeated_source is set true.
; http://www.php.net/manual/en/errorfunc.configuration.php#ini.ignore-repeated-errors
ignore_repeated_errors = Off

; Ignore source of message when ignoring repeated messages. When this setting
; is On you will not log errors with repeated messages from different files or
; source lines.
; http://www.php.net/manual/en/errorfunc.configuration.php#ini.ignore-repeated-source
ignore_repeated_source = Off

; Log errors to specified file. PHP's default behavior is to leave this value
; empty.
; http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-log
; Log errors to syslog or specified file (Event Log on NT, not valid in Windows 95).
;error_log = syslog
error_log = /var/log/apache/php_error_log

The file permissions for my php error log are:

[root at karsites apache]# ls -l php*
-rw-rw-rw- 1 root root 91472 2010-07-31 08:00 php_error_log
-rw-rw-rw- 1 root root     0 2008-05-29 13:30 php_error_log.skel
-rw-rw-rw- 1 root root     0 2008-05-29 13:30 php_mail_log
[root at karsites apache]#

If the PHP error log file is not set up correctly, then PHP 
will just output the errors to the apache error log file 
instead.

HTH

Keith Roberts



More information about the CentOS mailing list