php错误\u日志不工作

php错误\u日志不工作,php,error-logging,error-log,selinux,Php,Error Logging,Error Log,Selinux,这已经被问了1000次,我在发布之前浏览了不同的帖子,但没有找到答案。只要我一直在用PHP编程,这就一直是一场噩梦。有人能告诉我我做错了什么吗 我在ini文件中设置了error_log以及error_reporting=E_ALL | E_STRICT 我还缺什么?这通常是给我的。我希望此设置在ini文件中,而不是脚本中 另一件有趣的事情是,当我有意尝试在我的脚本中抛出一个错误时,Apache会一次又一次地重新启动 这是一个错误后的事件日志。按时间戳抢劫 Wed Nov 04 19:34:23

这已经被问了1000次,我在发布之前浏览了不同的帖子,但没有找到答案。只要我一直在用PHP编程,这就一直是一场噩梦。有人能告诉我我做错了什么吗

我在ini文件中设置了error_log以及error_reporting=E_ALL | E_STRICT

我还缺什么?这通常是给我的。我希望此设置在ini文件中,而不是脚本中

另一件有趣的事情是,当我有意尝试在我的脚本中抛出一个错误时,Apache会一次又一次地重新启动


这是一个错误后的事件日志。按时间戳抢劫

Wed Nov 04 19:34:23 2009] [notice] Apache/2.2.14 (Win32) PHP/5.3.0 configured -- resuming normal operations
[Wed Nov 04 19:34:23 2009] [notice] Server built: Sep 28 2009 22:41:08
[Wed Nov 04 19:34:23 2009] [notice] Parent: Created child process 1700
[Wed Nov 04 19:34:23 2009] [notice] Child 1700: Child process is running
[Wed Nov 04 19:34:23 2009] [notice] Child 3008: Released the start mutex
[Wed Nov 04 19:34:23 2009] [notice] Child 1700: Acquired the start mutex.
[Wed Nov 04 19:34:23 2009] [notice] Child 1700: Starting 64 worker threads.
[Wed Nov 04 19:34:23 2009] [notice] Child 1700: Starting thread to listen on port 80.
[Wed Nov 04 19:34:24 2009] [notice] Child 3008: All worker threads have exited.
[Wed Nov 04 19:34:24 2009] [notice] Child 3008: Child process is exiting
[Wed Nov 04 19:34:53 2009] [notice] Parent: child process exited with status 128 -- Restarting.
[Wed Nov 04 19:34:53 2009] [notice] Apache/2.2.14 (Win32) PHP/5.3.0 configured -- resuming normal operations
[Wed Nov 04 19:34:53 2009] [notice] Server built: Sep 28 2009 22:41:08
[Wed Nov 04 19:34:53 2009] [notice] Parent: Created child process 3656
[Wed Nov 04 19:34:53 2009] [notice] Child 3656: Child process is running
[Wed Nov 04 19:34:53 2009] [notice] Child 3656: Acquired the start mutex.
[Wed Nov 04 19:34:53 2009] [notice] Child 3656: Starting 64 worker threads.
[Wed Nov 04 19:34:53 2009] [notice] Child 3656: Starting thread to listen on port 80.
[Wed Nov 04 19:34:53 2009] [notice] Parent: child process exited with status 128 -- Restarting.
[Wed Nov 04 19:34:54 2009] [notice] Apache/2.2.14 (Win32) PHP/5.3.0 configured -- resuming normal operations
[Wed Nov 04 19:34:54 2009] [notice] Server built: Sep 28 2009 22:41:08
[Wed Nov 04 19:34:54 2009] [notice] Parent: Created child process 3980
[Wed Nov 04 19:34:54 2009] [notice] Child 3980: Child process is running
[Wed Nov 04 19:34:54 2009] [notice] Child 3980: Acquired the start mutex.
[Wed Nov 04 19:34:54 2009] [notice] Child 3980: Starting 64 worker threads.
[Wed Nov 04 19:34:54 2009] [notice] Child 3980: Starting thread to listen on port 80.
[Wed Nov 04 19:34:54 2009] [notice] Parent: child process exited with status 128 -- Restarting.
[Wed Nov 04 19:34:54 2009] [notice] Apache/2.2.14 (Win32) PHP/5.3.0 configured -- resuming normal operations
[Wed Nov 04 19:34:54 2009] [notice] Server built: Sep 28 2009 22:41:08
[Wed Nov 04 19:34:54 2009] [notice] Parent: Created child process 1600
[Wed Nov 04 19:34:54 2009] [notice] Child 1600: Child process is running
[Wed Nov 04 19:34:54 2009] [notice] Child 1600: Acquired the start mutex.
[Wed Nov 04 19:34:54 2009] [notice] Child 1600: Starting 64 worker threads.
[Wed Nov 04 19:34:54 2009] [notice] Child 1600: Starting thread to listen on port 80.
[Wed Nov 04 19:34:55 2009] [notice] Parent: child process exited with status 128 -- Restarting.
[Wed Nov 04 19:34:55 2009] [notice] Apache/2.2.14 (Win32) PHP/5.3.0 configured -- resuming normal operations
[Wed Nov 04 19:34:55 2009] [notice] Server built: Sep 28 2009 22:41:08
[Wed Nov 04 19:34:55 2009] [notice] Parent: Created child process 1068
[Wed Nov 04 19:34:55 2009] [notice] Child 1068: Child process is running
[Wed Nov 04 19:34:55 2009] [notice] Child 1068: Acquired the start mutex.
[Wed Nov 04 19:34:55 2009] [notice] Child 1068: Starting 64 worker threads.
[Wed Nov 04 19:34:55 2009] [notice] Child 1068: Starting thread to listen on port 80.
[Wed Nov 04 19:34:55 2009] [notice] Parent: child process exited with status 128 -- Restarting.
[Wed Nov 04 19:34:55 2009] [notice] Apache/2.2.14 (Win32) PHP/5.3.0 configured -- resuming normal operations
[Wed Nov 04 19:34:55 2009] [notice] Server built: Sep 28 2009 22:41:08
[Wed Nov 04 19:34:55 2009] [notice] Parent: Created child process 3220
[Wed Nov 04 19:34:56 2009] [notice] Child 3220: Child process is running
[Wed Nov 04 19:34:56 2009] [notice] Child 3220: Acquired the start mutex.
[Wed Nov 04 19:34:56 2009] [notice] Child 3220: Starting 64 worker threads.
[Wed Nov 04 19:34:56 2009] [notice] Child 3220: Starting thread to listen on port 80.

您还需要在php.ini中设置
log\u errors=On

确保并设置

display_errors = On
试一试

 error_reporting(E_ALL);
在你的代码中。通常情况下,我会包含一个运行时错误配置脚本,该脚本在开发时打开错误,在不开发时关闭错误。大致如下所示:

if ($debugmode == 'on') {
    error_reporting(E_ALL); 
    ini_set("display_errors", 1);
}else { 
    error_reporting(0); 
    ini_set("display_errors", 0);
}
希望这有帮助


**我没有读对,你想记录错误而不是显示,在这种情况下,混沌的答案就是你要找的

我不明白为什么,但错误日志现在正在运行。这就是我所做的。我放弃并注释掉了error_log指令并关闭了ini文件。我运行了带有解析错误的脚本,以查看Apache是否仍然会崩溃,我在日志文件中得到了PHP错误。这很奇怪,因为ini文件不再启用错误日志,而且我的脚本没有使用ini\u set()


有人能解释这种疯狂吗?此外,Apache不再崩溃。

如果设置了error\u log指令,该文件将用于记录php错误,如果未设置,错误将记录到Apache日志中。看一看

运行Apache的用户必须能够写入错误日志文件及其所在的目录。如果没有创建该文件,可能是由于权限问题


我不知道为什么Apache会在你身上崩溃,但我猜这是某种权限问题。

正如bradym所说,检查你是否对Apache用户php错误日志所在的目录拥有写入权限。如果您创建了一个具有写入权限的日志文件,这是不够的,目录也应该具有这些权限。

错误\u log=“C:\php\log\error.log”对我也不起作用。我的解决方案是,您不应该自己创建error.log,因为PHP会帮您完成。我在Windows 2008服务器上使用PHP5.2,遇到的问题是我指定的错误日志是写保护的。我所有的.htaccess设置都是正确的,PHP无法写入错误日志,因为它没有权限。这就为我解决了问题:

chmod 777 watermellon-app-errors.log

显然,您需要将.log更改为用于日志的任何文件

如果其他任何人在让本地开发环境记录错误时遇到问题,下面是为我解决问题的方法:

在windows上,必须将
error\u log
设置为日志的完整路径,以便
error\u log()
工作(
error\u log=c:\apache\php\u errors.log
)。但是,如果没有路径的
error\u log=php\u errors.log
,php仍然能够记录启动错误,例如

PHP Startup: Unable to load dynamic library 'ext\php_mysqli.dll' - The specified module could not be found

它在我的ubuntu(Apache 2.4.7,PHP 5.5.9)上的工作方式如下:

命令行脚本:

  • 如果
    log\u errors=On
    ,则将日志写入
    error\u log
    指向的路径。
    /etc/php5/cli/php.ini中的设置
    
通过apache的web请求:

  • 如果
    log\u errors=On
    /etc/php5/apache2/php.ini
    ),则错误会附加到虚拟主机中的
    ErrorLog
    apache指令所指向的路径中。如果该指令不存在,则使用php.ini
    error\u log
    路径
  • 如果
    log\u errors=Off
    不在任何地方写入日志

就我所记得的,它在大多数linux堆栈中几乎都是这样工作的

如果您使用Fedora,SELinux(默认启用)将防止apache/httpd将错误附加到日志文件中,即使您的文件是在php.ini中指定的,并且其包含目录具有所有允许的权限

通过查看/var/log/messages

理想的解决方案是将SELinux配置为允许访问日志文件

更快的解决方案是通过将SELinux设置为disabled,在/etc/SELinux/config中禁用SELinux

完成此操作后,您需要重新启动系统才能使更改生效

检查PHP-FPM是否未明确设置错误日志: 确保文件
/etc/php fpm.d/www.conf
不包含错误日志的
php\u admin\u值
设置。搜索以下内容并使用分号将其注释掉:

; NOTE: If these are set, ini_set('error_log', 'path') will have no effect 
; inside your php code, and this will be forced to be the value always.
; php_admin_value[error_log] = /var/log/php-fpm/www-error.log
; php_admin_flag[log_errors] = on
然后重新启动php fpm:

systemctl restart php-fpm
检查Apache.htaccess文件是否未使用 无法覆盖apache配置文件中的
php\u admin\u值
设置,因此请确保apache配置文件中的
错误日志
设置没有任何php\u admin\u值。同时检查
php\u值
设置,以防万一


在我的例子中,在CentOS development server上,经过完整的
yum更新后,/var/log/http上的权限更改为700,用户更改为“root”,因此用户“apache”无法输入或写入。它仍然能够写入现有文件/var/log/httpd/error.log,但无法创建新文件,因为我使用了带有日期后缀的日志文件。
发出命令

chown apache /var/log/httpd

解决了问题。

这对我来说是个好办法

setsebool -P httpd_unified 1
请注意,这将是以下首选方法,请首先尝试:

semanage fcontext -a -t httpd_sys_rw_content_t 'errorLogNameHere.error.log
restorecon -v 'errorLogNameHere.error.log'
这是德里夫的回答
journalctl -xe 
$ chmod 0777 -R /var/log/apache2
$ apachectl restart