php 在哪里可以找到错误日志文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12834583/
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 can I find error log files?
提问by user1010966
Where can I find error log files? I need to check them for solving an internal server error shown after installing suPHP.
在哪里可以找到错误日志文件?我需要检查它们以解决安装 suPHP 后显示的内部服务器错误。
回答by omoser
You can use "lsof" to find open logfiles on your system. lsof just gives you a list of all open files.
您可以使用“lsof”来查找系统上打开的日志文件。lsof 只是为您提供所有打开文件的列表。
Use grep for "log" ... use grep again for "php" (if the filename contains the strings "log" and "php" like in "php_error_log" and you are root user you will find the files without knowing the configuration).
将 grep 用于“log”...再次将 grep 用于“php”(如果文件名包含字符串“log”和“php”,例如“php_error_log”,并且您是 root 用户,您将在不知道配置的情况下找到这些文件) .
root@lnx-work:~# lsof |grep log
... snip
gmain 12148 12274 user 13r REG 252,1 32768 661814 /home/user/.local/share/gvfs-metadata/home-11ab0393.log
gmain 12148 12274 user 21r REG 252,1 32768 662622 /home/user/.local/share/gvfs-metadata/root-56222fe2.log
gvfs-udis 12246 user mem REG 252,1 55384 790567 /lib/x86_64-linux-gnu/libsystemd-login.so.0.7.1
==> apache 12333 user mem REG 252,1 55384 790367 /var/log/http/php_error_log**
... snip
root@lnx-work:~# lsof |grep log |grep php
**apache 12333 user mem REG 252,1 55384 790367 /var/log/http/php_error_log**
... snip
Also see this article on finding open logfiles: Find open logfiles on a linux system
另请参阅有关查找打开的日志文件的文章: 在 linux 系统上查找打开的日志文件
回答by RDK
Works for me. How log all php errors to a log fiie?
为我工作。如何将所有 php 错误记录到日志文件中?
Just add following line to /etc/php.ini to log errors to specified file – /var/log/php-scripts.log
只需将以下行添加到 /etc/php.ini 以将错误记录到指定文件 – /var/log/php-scripts.log
vi /etc/php.ini
Modify error_log directive
修改 error_log 指令
error_log = /var/log/php-scripts.log
Make sure display_errors set to Off (no errors to end users)
确保 display_errors 设置为 Off (最终用户没有错误)
display_errors = Off
Save and close the file. Restart web server:
保存并关闭文件。重启网络服务器:
/etc/init.d/httpd restart
How do I log errors to syslog or Windows Server Event Log?
如何将错误记录到系统日志或 Windows Server 事件日志?
Modify error_log as follows :
修改 error_log 如下:
error_log = syslog
How see logs?
怎么看日志?
Login using ssh or download a log file /var/log/php-scripts.log using sftp:
$ sudo tail -f /var/log/php-scripts.log
回答by Bradley Flood
On CentoS with cPanel installed my logs were in:
在安装了 cPanel 的 CentoS 上,我的日志位于:
/usr/local/apache/logs/error_log
/usr/local/apache/logs/error_log
To watch: tail -f /usr/local/apache/logs/error_log
观看: tail -f /usr/local/apache/logs/error_log
回答by hiasl86
What OS you are using and which Webserver? On Linux and Apache you can find the apache error_log in /var/log/apache2/
您使用的是什么操作系统以及哪个 Web 服务器?在 Linux 和 Apache 上,您可以在 /var/log/apache2/ 中找到 apache error_log
回答by AnukuL
I am using Cent OS 6.6with Apacheand for me error log files are in
我正在使用Cent OS 6.6和Apache,对我来说错误日志文件在
/usr/local/apache/log
/usr/local/apache/log
回答by mopsyd
This is a preferable answer in most use cases, because it allows you to decouple execution of the software from direct knowledge of the server platform, which keeps your code much more portable. If you are doing a lot of cron/cgi, this may not help directly, but it can be set into a config at web runtime that the cron/cgi scripts pull from to keep the log location consistent in that case.
在大多数用例中,这是一个更可取的答案,因为它允许您将软件的执行与服务器平台的直接知识分离,从而使您的代码更具可移植性。如果您正在执行大量 cron/cgi,这可能没有直接帮助,但可以在 web 运行时将其设置为 cron/cgi 脚本从中提取的配置,以在这种情况下保持日志位置一致。
You can get the current log file assigned natively to php on any platform at runtime by using:
您可以在运行时使用以下命令在任何平台上获取本地分配给 php 的当前日志文件:
ini_get('error_log');
This returns the value distributed directly to the php binary by the webserver, which is what you want in 90% of use cases (with the glaring exception being cgi). Cgi will often log to this same location as the http webserver client, but not always.
这将返回由 web 服务器直接分发到 php 二进制文件的值,这是您在 90% 的用例中想要的(明显的例外是 cgi)。Cgi 通常会登录到与 http 网络服务器客户端相同的位置,但并非总是如此。
You will also want to check that it is writeable before committing anything to it to avoid errors. The conf file that defines it's location (typically either apache.conf globally or vhosts.conf on a per-domain basis), but the conf does not ensure that file permissions allow write access at runtime.
您还需要在向其提交任何内容之前检查它是否可写以避免错误。定义其位置的 conf 文件(通常是全局 apache.conf 或基于每个域的 vhosts.conf),但 conf 不确保文件权限允许在运行时进行写访问。
回答by Pratik Mehta
This will defiantly help you,
这将坚定地帮助你,
https://davidwinter.me/enable-php-error-logging/
https://davidwinter.me/enable-php-error-logging/
OR
或者
In php.ini: (vim /etc/php.ini Or Sudo vim /usr/local/etc/php/7.1/php.ini)
display_errors = Off
log_errors = On
error_log = /var/log/php-errors.log
在 php.ini 中:(vim /etc/php.ini 或 Sudo vim /usr/local/etc/php/7.1/php.ini)
display_errors = 关闭
log_errors = 开
error_log = /var/log/php-errors.log
Make the log file, and writable by www-data:
制作日志文件,并由 www-data 写入:
sudo touch /var/log/php-errors.log
/var/log/php-errors.log
sudo chown :www
须藤触摸/var/log/php-errors.log
/var/log/php-errors.log
须藤 chown :www
Thanks,
谢谢,
回答by NVRM
For unix cli users:
对于 unix cli 用户:
Most probably the error_log ini entry isn't set. To verify:
很可能没有设置 error_log ini 条目。验证:
php -i | grep error_log
// error_log => no value => no value
You can either set it in your php.ini cli file, or just simply quickly pipe all STDERRyourself to a file:
你可以在你的 php.ini cli 文件中设置它,或者只是简单地将所有STDERR自己快速传输到一个文件中:
./myprog 2> myerror.log
Then quickly:
然后很快:
tail -f myerror.log

