我在共享主机上,有cPanel, Apache, PHP是由FastCGI运行的。PHP在哪里存储错误日志?

是否有其他方法可以在共享主机环境中找到错误日志,而不必通过整个站点结构来查找error_log文件?

我可以访问PHP .ini文件(我使用PHP 5.2.16版本)。


当前回答

因为某种原因,我把它存储在:

/ var / log / php-errors日志。

我使用的是Ubuntu Server 16.04 (Xenial Xerus)和PHP 7.1.28。

其他回答

如果PHP是apache2模块,PHP将错误日志存储在/var/log/apache2中。 共享主机通常将日志文件存储在根目录/日志子文件夹中。 但是…如果你可以访问php.ini文件,你可以这样做:

error_log = /var/log/php-scripts.log

根据rinogo的评论:如果您正在使用cPanel,您可能正在寻找的主日志文件(默认情况下)存储在

/usr/local/apache/logs/error_log

如果所有这些都失败了,您可以使用

<?php phpinfo(); ?>

我可以向你保证,我不是唯一一个在沮丧地寻找日志文件时被逼疯过的人。看起来它应该是整个系统中最容易找到的东西。

关于PHP错误日志存储位置的明确指南将是一项复杂的工作。官方的PHP手册甚至没有尝试解决整个主题,因为PHP之外的系统存在依赖关系,例如操作系统(Linux vs. Windows, Linux的哪个发行版),包括Windows和Linux中的设置,这些设置会影响PHP错误日志的名称和位置。

在有人花时间写一份完整的、跨系统的指南之前,你能得到的最好的是你可以查询的大致方向。每个PHP开发人员都不得不忍受这种追求带来的痛苦,只有一个例外。如果你在一个地方工作,信息是在你第一次需要的时候提供的,那么你永远都需要这些信息,也就是说,直到你找到一个新的工作环境。有这么幸运的人。

如果这些信息不是直接提供给你的,也就是说,你还有一些事情要做。在你的职业生涯中,寻找工作不是最漫长的,但也不是最简单的。

从已经发布的许多答案中可以明显看出,一个明智的开始是phpinfo()的输出。要查看它,创建一个包含以下内容的PHP文件:

<?php
    phpinfo();

Either browse to that file or run it from the command line. If you do both, you likely will find the error_log is in different places, depending on command line vs. web server use of PHP. That is because the PHP interpreter that runs on a web server is not the same PHP interpreter that runs from the command line, even when the command line is on the same machine as the web server. The answers already posted in here mostly are making an unstated assumption that PHP is running as part of a web server.

error_log的默认值是无值

无论值是什么,它都来自于用于配置PHP的PHP. ini文件。可以有很多php.ini文件。一开始在它们之间寻找方法是令人困惑的,但是您不需要处理这些来找到您的PHP日志。

如果phpinfo()的输出显示了一个文件的完整路径,那么这就是日志所在的位置。你真幸运。

诀窍在于phpinfo()中通常没有指定完整的路径。当没有完整路径时,位置取决于:

Whether error_log is no value. If it is, the log file location will depend on the operating system and the mode PHP is running. If PHP is running as an Apache module, on Linux the log often is in /var/log/apache2/error.log. Another likely spot is in a logs directory in your account home directory, ~/logs/error.log. If there is a file name without a path, the location depends on whether the file name has the value syslog. If it syslog, then the PHP error log is injected into the syslog for the server, which varies by Linux distribution. A common location is /var/log/syslog, but it can be anywhere. Even the name of the syslog varies by distribution. If the name without a path is not syslog, a frequent home for the file is is the document root of the website (a.k.a., website home directory, not to be confused with the home directory for your account).

这个小抄在某些情况下是有帮助的,但我很遗憾地承认它并不是万能的。我向你表示哀悼。

Linux

php --info | grep error 

终端将输出错误日志位置。

窗户

php --info | findstr /r /c:"error_log"

命令提示符将输出错误日志位置。

命令,设置日志的位置

打开php.ini并添加以下行:

error_log = /log/myCustomLog.log

感谢chelmertz和Boom对这个问题的评论。

如果您在谷歌计算引擎中,也可以是/var/log/apache2/error.log。

你可以这样看尾巴:

tail -f /var/log/apache2/error.log

WordPress

当WP_DEBUG_LOG设置为true时,WordPress会将error_log()消息直接指向/wp-content/debug.log。

请参阅WordPress文档中的WP_DEBUG_LOG