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

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

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


当前回答

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

你可以这样看尾巴:

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

其他回答

在命令行中输入cat <file location> | grep ErrorLog在httpd.conf文件中查找ErrorLog。例如:

cat /etc/apache2/httpd.conf | grep ErrorLog

输出:

# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
ErrorLog "/private/var/log/apache2/error_log"

找到以ErrorLog开头的行,这就是答案。

注意:对于虚拟主机,您可以编辑虚拟主机文件httpd-vhosts.conf以指定不同的日志文件位置。

在php.ini中配置错误日志文件时,可以使用绝对路径或相对路径。相对路径将基于生成脚本的位置进行解析,并且您将在拥有脚本的每个目录中获得一个日志文件。如果希望所有错误消息都保存在同一个文件中,请使用该文件的绝对路径。

请参阅错误处理函数。

Linux

php --info | grep error 

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

窗户

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

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

命令,设置日志的位置

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

error_log = /log/myCustomLog.log

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

尝试phpinfo()并检查“error_log”

在共享的cPanel环境中,如果你的主机提供商没有在cPanel仪表板中提供任何选项,你就无法找到错误日志。你可以搜索“错误”,看看你的提供商是否有任何错误。

否则,您通常会在public_html文件中找到一个名为“error_log”的文件,其中记录了所有PHP错误。