我在共享主机上,有cPanel, Apache, PHP是由FastCGI运行的。PHP在哪里存储错误日志?
是否有其他方法可以在共享主机环境中找到错误日志,而不必通过整个站点结构来查找error_log文件?
我可以访问PHP .ini文件(我使用PHP 5.2.16版本)。
我在共享主机上,有cPanel, Apache, PHP是由FastCGI运行的。PHP在哪里存储错误日志?
是否有其他方法可以在共享主机环境中找到错误日志,而不必通过整个站点结构来查找error_log文件?
我可以访问PHP .ini文件(我使用PHP 5.2.16版本)。
当前回答
最好的方法是查看httpd.conf文件,看看默认值是什么。它也可以被特定的虚拟主机覆盖。我首先查看/etc/httpd/conf/httpd.conf或/etc/apache2/httpd.conf并搜索error_log。它可以被列出为/var/log/httpd/error_log或/var/log/apache2/error_log,但也可以简单地列出为logs/error_log。
在这种情况下,它是一个相对路径,这意味着它将在/etc/httpd/logs/error_log下。如果仍然找不到它,请检查httpd.conf文件的底部,并查看虚拟主机包含在哪里。它可能在/etc/httpd/conf中。D / <-作为“其他”或“额外”。你的虚拟主机可以用ErrorLog "/path/to/error_log"覆盖它。
其他回答
我可以向你保证,我不是唯一一个在沮丧地寻找日志文件时被逼疯过的人。看起来它应该是整个系统中最容易找到的东西。
关于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).
这个小抄在某些情况下是有帮助的,但我很遗憾地承认它并不是万能的。我向你表示哀悼。
默认情况下,PHP似乎不会在任何地方记录错误。在我看到的所有安装中,php.ini中的error_log键都被注释掉了。
通常我:
寻找php.ini文件。找到php . ini。 在这些文件中搜索error_reporting值; 它应该被设置为PHP日志级别的任意组合。 例如:E_ALL & ~E_DEPRECATED & ~E_STRICT 检查error_log值,确保它指向一个实际的位置,没有被注释掉。 默认值没有给出完整的路径,只有一个文件名,我不知道这个路径通常解析到哪里。可能/var/log/.
在php.ini中配置错误日志文件时,可以使用绝对路径或相对路径。相对路径将基于生成脚本的位置进行解析,并且您将在拥有脚本的每个目录中获得一个日志文件。如果希望所有错误消息都保存在同一个文件中,请使用该文件的绝对路径。
请参阅错误处理函数。
对于CentOS 8,它是var/log/httpd/error_log。
如果您在谷歌计算引擎中,也可以是/var/log/apache2/error.log。
你可以这样看尾巴:
tail -f /var/log/apache2/error.log