我在共享主机上,有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版本)。
当前回答
php --info | grep error
这很有帮助。
其他回答
我可以向你保证,我不是唯一一个在沮丧地寻找日志文件时被逼疯过的人。看起来它应该是整个系统中最容易找到的东西。
关于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).
这个小抄在某些情况下是有帮助的,但我很遗憾地承认它并不是万能的。我向你表示哀悼。
您处于共享环境中,无法找到错误日志。总是检查你的cPanel仪表板是否有错误选项。如果您无法找到错误日志,那么您可以在那里找到它。
在cPanel搜索栏中,搜索Error,它将显示Error Pages,这基本上是不同HTTP错误页面的列表,其他Error是错误日志显示的地方。
共享环境中的其他地方:
/ home / yourusername / logs / home / yourusername / public_html error_log
最好的方法是查看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"覆盖它。
如果您在谷歌计算引擎中,也可以是/var/log/apache2/error.log。
你可以这样看尾巴:
tail -f /var/log/apache2/error.log
对于PHP-FPM,只需搜索配置文件error_log:
cat /etc/php-fpm.d/www.conf | grep error_log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log