简体   繁体   English

如果 error_log 指令只是说“error_log”,那么 PHP 错误记录在哪里?

[英]Where are PHP errors logged to if the error_log directive simply says “error_log”?

I ran phpinfo() and the error_log directive simply says error_log .我运行了phpinfo()并且error_log指令只是说error_log What file is that referring to?那是指什么文件? ie what would the full path to the error_log be?error_log的完整路径是什么?

Quote from the documentation : 从文档中引用:

error_log string错误日志字符串

Name of the file where script errors should be logged.应记录脚本错误的文件的名称。 The file should be writable by the web server's user.该文件应该可由 Web 服务器的用户写入。 If the special value syslog is used, the errors are sent to the system logger instead.如果使用特殊值 syslog,错误将发送到系统记录器。 On Unix, this means syslog(3) and on Windows NT it means the event log.在 Unix 上,这意味着 syslog(3) 而在 Windows NT 上,它意味着事件日志。 The system logger is not supported on Windows 95. See also: syslog(). Windows 95 不支持系统记录器。另请参阅:syslog()。 If this directive is not set, errors are sent to the SAPI error logger.如果未设置此指令,则会将错误发送到 SAPI 错误记录器。 For example, it is an error log in Apache or stderr in CLI.例如,它是 Apache 中的错误日志或 CLI 中的 stderr。

So, when the value is not set (which is the default) it will be sent to the parent error logger, which is apache (if run via it) or stderr if you run the script on the command line.因此,当未设置该值(这是默认值)时,它将被发送到父错误记录器,即 apache(如果通过它运行)或stderr如果您在命令行上运行脚本)。

If you use the script via apache you will have to look at the apache error log, usually in /var/log/apache or /var/log/httpd , depending on your distribution.如果您通过 apache 使用该脚本,则必须查看 apache 错误日志,通常位于/var/log/apache/var/log/httpd ,具体取决于您的发行版。 You can check the apache configuration file for the exact location.您可以检查 apache 配置文件以获取确切位置。

Edit:编辑:

I just noticed I misread your question, I guess you mean error_log has the actual value error_log ?我只是注意到我误读了您的问题,我猜您的意思是error_log具有实际值error_log

I just did some testing.我只是做了一些测试。 When I set error_log to a value like php_errors.log PHP still writes the error messages to the apache error log.当我将error_log设置为php_errors.log类的值时,PHP 仍会将错误消息写入 apache 错误日志。 It behaves as if the value was empty.它的行为就像该值是空的一样。 When I set the value to a full path (eg /tmp/php_errors.log ) then it writes the errors to the specified file.当我将该值设置为完整路径(例如/tmp/php_errors.log )时,它会将错误写入指定的文件。

So I guess in your case it writes the errors to the apache error log file.所以我猜在你的情况下它会将错误写入 apache 错误日志文件。

Of course you can set your own log file be adding当然你可以设置自己的日志文件来添加

ini_set("error_log", "/tmp/php_errors.log");

to your PHP files where you need it (if it hasn't been disabled by an administrator).到您需要它的 PHP 文件(如果它没有被管理员禁用)。

When the value simply says error_log (or error_log = error_log in your php.ini file), that means the errors will be written to a file called error_log in the same directory that the error occurs.当该值仅表示error_log (或php.ini文件中的error_log = error_log )时,这意味着错误将写入发生错误的同一目录中名为error_log的文件中。

So, if you have a file called index.php in /home/user/public_html/ that throws an error, the error will be written to: /home/user/public_html/error_log .因此,如果您在/home/user/public_html/中有一个名为index.php的文件引发错误,则错误将写入: /home/user/public_html/error_log

If you have file called resize.php in /home/user/public_html/admin/images/ that throws an error, then the errors will be written to: /home/user/public_html/admin/images/error_log如果/home/user/public_html/admin/images/中有名为resize.php引发错误,则错误将写入: /home/user/public_html/admin/images/error_log


Source: Display and log errors for PHP来源: PHP 的显示和记录错误

On Windows 10, IIS 10.0.18362.1,在 Windows 10 上,IIS 10.0.18362.1,
I set in php\\php.ini :我在php\\php.ini设置:

error_log = "C:\tmp\php_errors.log"  

or或者

error_log = C:\tmp\php_errors.log  

or或者

error_log = \tmp\php_errors.log  

phpinfo() shows : phpinfo() 显示:

error_log C:\\tmp\\php_errors.log or \\tmp\\php_errors.log error_log C:\\tmp\\php_errors.log 或 \\tmp\\php_errors.log

Sometimes directly, but always after iisreset (recycling the application pool).有时直接,但总是在iisreset (回收应用程序池)之后。

That is where the file is saved.那就是保存文件的地方。

Without pad : error_log = php_errors.log it will be written where the error occurs.没有 pad : error_log = php_errors.log它将被写入发生错误的地方。 Has already been mentioned.已经提到了。

打开你的 php.ini 文件检查 error_log 的路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM