PHP 通过 CLI 成功地将错误日志记录到 /var/log/php_errors.log。
但 Apache + PHP 却无法记录错误。
[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
我在 php.ini 文件中有以下配置:
display_errors = On
error_reporting = E_ALL | E_STRICT
log_errors = On
error_log = php_errors.log
在 httpd.conf 文件中:
ErrorLog "/var/log/httpd/error_log"
权限:
[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*
正如您所见,Apache 守护程序有权限写入日志文件。
/var/log/php_errors.log 和 /var/log/httpd/error_log 中仍然没有来自 Apache 或 PHP 的错误。
更新1。
在 php.ini 中更改了此行:
error_log = php_errors.log
转换为完整路径:
error_log = /var/log/php_errors.log
权限已经正常。但如果有人也遇到问题,你可以将日志文件的权限设置为0777或更改文件所有者来进行调试。
php_admin_value error_reporting 'E_ALL&〜E_STRICT'
。 - pevik