PHP 在哪里存储错误日志?(php5, apache, fastcgi, cpanel)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5127838/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where does PHP store the error log? (php5, apache, fastcgi, cpanel)
提问by PHPLOVER
I am on shared hosting and have Cpanel, Apache, PHP is run by fastcgi. Where does PHP store the error log?
我在共享主机上,并且有 Cpanel、Apache、PHP 由 fastcgi 运行。PHP 在哪里存储错误日志?
Is there any other way I can find the error log on shared hosting environment instead of having to go through entire site structure to look for error_log files?
有没有其他方法可以在共享托管环境中找到错误日志,而不必遍历整个站点结构来查找 error_log 文件?
I have access to the php.ini
(I am using PHP version 5.2.16).
我可以访问php.ini
(我使用的是 PHP 5.2.16 版)。
采纳答案by Adam Arold
PHP stores error logs in /var/log/apache2
if PHP is an apache2 module.
Shared hosts are often storing log files in your root directory /log
subfolder.
But...if you have access to a php.ini
file you can do this:
/var/log/apache2
如果 PHP 是 apache2 模块,则 PHP 会存储错误日志。共享主机通常将日志文件存储在您的根目录/log
子文件夹中。但是...如果您有权访问php.ini
文件,则可以执行以下操作:
error_log = /var/log/php-scripts.log
According to rinogo's comment: If you're using cPanel, the master log file you're probably looking for is stored (by default) at
根据rinogo的评论:如果您使用的是 cPanel,则您可能正在查找的主日志文件(默认情况下)存储在
/usr/local/apache/logs/error_log
If all else fails you can check the location of the log file using
如果所有其他方法都失败了,您可以使用以下命令检查日志文件的位置
<?php phpinfo(); ?>
回答by chelmertz
Try phpinfo()
and check for "error_log"
尝试phpinfo()
检查“error_log”
回答by Cullub
Linux
Linux
php --info | grep error
The terminal will output the error log location.
终端会输出错误日志位置。
Windows
视窗
php --info | findstr /r /c:"error_log"
The command prompt will output the error log location
命令提示符会输出错误日志位置
To set the log location
设置日志位置
Open your php.ini
and add the following line:
打开您的php.ini
并添加以下行:
error_log = /log/myCustomLog.log
Thanks @chelmertez, @Boomfor these (comments on the question).
感谢@chelmertez和@Boom(对问题的评论)。
回答by Allie
On a LAMP environment the php errors are default directed to this below file.
在 LAMP 环境中,php 错误默认指向以下文件。
/var/log/httpd/error_log
All access logs come under:
所有访问日志都位于:
/var/log/httpd/access_log
回答by Eric Leschinski
How do find your PHP error log on Linux:
如何在 Linux 上找到您的 PHP 错误日志:
eric@dev /var $ sudo updatedb
[sudo] password for eric:
eric@dev /var $ sudo locate error_log
/var/log/httpd/error_log
Another equivalent way:
另一种等效方式:
eric@dev /home/eric $ sudo find / -name "error_log" 2>/dev/null
/var/log/httpd/error_log
回答by ThorSummoner
It appears that by default php does not logerrors anywhere, the error_log
key in php.ini is commented out in all the install's I've seen.
似乎默认情况下 php不会在任何地方记录错误,error_log
php.ini 中的键在我见过的所有安装中都被注释掉了。
Generally I:
一般我:
- look for php.ini files.
locate php.ini
. Search these files for the
error_reporting
value;Which should be set to whatever amalgamation of php log levels are enough for you.,
Eg:
E_ALL & ~E_DEPRECATED & ~E_STRICT
Check the
error_log
value to make sure it points to an actual place and is not commented out.The default value doesn't give a full path, only a file name, I don't know where this path resolves to normally. Probably
/var/log/
.
- 寻找 php.ini 文件。
locate php.ini
. 在这些文件中搜索
error_reporting
值;哪个应该设置为 php 日志级别的任何合并对您来说就足够了。,
例如:
E_ALL & ~E_DEPRECATED & ~E_STRICT
检查该
error_log
值以确保它指向实际位置并且没有被注释掉。默认值没有给出完整路径,只有文件名,我不知道这个路径通常解析到哪里。大概
/var/log/
。
回答by mailo
You should use absolute path when setting error_logvariable in your php.ini file, otherwise, error logs will be stored according to your relative path.
在 php.ini 文件中设置error_log变量时应使用绝对路径,否则错误日志将根据您的相对路径存储。
error_log = /var/log/php.errors
Other solution would be writing simple script which would list all error logs files from directory tree.
其他解决方案是编写简单的脚本,该脚本将列出目录树中的所有错误日志文件。
回答by Vivek
It can also be /var/log/apache2/error.log
if you are in google compute engine.
/var/log/apache2/error.log
如果您在谷歌计算引擎中,也可能是这样。
And you can view tail like this:
你可以像这样查看尾巴:
tail -f /var/log/apache2/error.log
回答by Thomas Bennett
The best way is to look in your httpd.conf file and see what the default is. It could also be overridden by your specific virtual host. I start by looking at /etc/httpd/conf/httpd.conf
or /etc/apache2/httpd.conf
and search for error_log. It could be listed as either /var/log/httpd/error_log or /var/log/apache2/error_log
but it might also be listed as simply logs/error_log
.
最好的方法是查看您的 httpd.conf 文件并查看默认值。它也可以被您的特定虚拟主机覆盖。我首先查看/etc/httpd/conf/httpd.conf
or/etc/apache2/httpd.conf
并搜索 error_log。它可以列为 /var/log/httpd/error_log /var/log/apache2/error_log
,也可能列为简单的logs/error_log
.
In this case it is a relative path, which means it will be under /etc/httpd/logs/error_log
. If you still can't find it check the bottom of your httpd.conf file and see where your virtual hosts are included. It might be in /etc/httpd/conf.d/<- as "other" or "extra". Your virtual host could override it then with ErrorLog "/path/to/error_log".
在这种情况下,它是一个相对路径,这意味着它将在/etc/httpd/logs/error_log
. 如果您仍然找不到它,请检查您的 httpd.conf 文件的底部并查看您的虚拟主机的位置。它可能在 /etc/httpd/conf.d/<- 中作为“其他”或“额外”。然后您的虚拟主机可以使用 ErrorLog "/path/to/error_log" 覆盖它。
回答by Abhishek
If you have build Apache and PHP from source, then the error logs by default is generated at your ${Apache install dir}/logs/error_log
i.e generally /usr/local/apache2/logs/error_log
. Else, if you have installed it from repository, you will find it at /var/log/apache2/error_log
.You can set the path in your php.ini
also and verify it by invoking phpinfo()
.
如果您从源代码构建了 Apache 和 PHP,那么默认情况下错误日志会在您的${Apache install dir}/logs/error_log
ie 中生成/usr/local/apache2/logs/error_log
。否则,如果您已从存储库安装它,您将在 中找到它。/var/log/apache2/error_log
您可以在您的php.ini
还中设置路径并通过调用来验证它phpinfo()
。