php php返回500错误但没有错误日志

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7149030/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:09:29  来源:igfitidea点击:

php return 500 error but no error log

phpapacheloggingerror-handling

提问by ryanzec

I am having an issue when I have a php application that is returning an internal server error (500) however nothing is showing up in the error log.

当我有一个返回内部服务器错误 (500) 的 php 应用程序但错误日志中没有显示任何内容时,我遇到了问题。

Now I know there are error with what I am trying to run, I know I have missing some files and what not but something should show in the apache error log (otherwise how are I supposed to know exactly what I am missing).

现在我知道我正在尝试运行的内容存在错误,我知道我丢失了一些文件,但有些东西应该显示在 apache 错误日志中(否则我应该如何确切地知道我丢失了什么)。

I created a test script is errors it in under the same vhost configuration and those error show up fine so everything seems configured right as far as php/apache. Are there certain php errors that does show up in the error log (php is configure to display any type of notice, warning, , error, fatal error, etc...)?

我创建了一个测试脚本,在相同的 vhost 配置下出现错误,这些错误显示正常,因此就 php/apache 而言,一切似乎都配置正确。错误日志中是否显示某些 php 错误(php 配置为显示任何类型的通知、警告、错误、致命错误等...)?

This is running on ubunut 10.04 with the standard apache and php from the ubuntu repo with apt-get.

这是在 ubunut 10.04 上运行的,使用 apt-get 的 ubuntu 存储库中的标准 apache 和 php。

采纳答案by Luc M

Scan your source files to find @.

扫描您的源文件以查找@.

From php documentation site

来自 php 文档站点

Currently the "@" error-control operator prefix will even disable error reporting for critical errors that will terminate script execution. Among other things, this means that if you use "@" to suppress errors from a certain function and either it isn't available or has been mistyped, the script will die right there with no indication as to why.

目前,“@”错误控制运算符前缀甚至会禁用将终止脚本执行的严重错误的错误报告。除其他外,这意味着如果您使用“@”来抑制某个函数的错误并且它不可用或输入错误,脚本将立即死在那里,没有任何迹象表明原因。

回答by Meloman

Copy and paste the following into a new .htaccessfile and place it on your website's root folder :

将以下内容复制并粘贴到一个新.htaccess文件中,并将其放在您网站的根文件夹中:

php_flag  display_errors                  on
php_flag  display_startup_errors          on

Errors will be shown directly in your page.

错误将直接显示在您的页面中。

That's the best way to debug quickly but don't use it for long timebecause it could be a security breach.

这是快速调试的最佳方法,但不要长时间使用它,因为它可能会破坏安全。

回答by akirk

Maybe something turns off error output. (I understand that you are trying to say that other scripts properly output their errors to the errorlog?)

也许有些东西会关闭错误输出。(我知道您是想说其他脚本正确地将它们的错误输出到错误日志中?)

You could start debugging the script by determining where it exits the script (start by adding a echo 1; exit;to the first line of the script and checking whether the browser outputs 1and then move that line down).

您可以通过确定它退出脚本的位置来开始调试脚本(首先将 a 添加echo 1; exit;到脚本的第一行并检查浏览器是否输出1,然后将该行向下移动)。

回答by sgnsajgon

In the past, I had no error logs in two cases:

过去,我在两种情况下都没有错误日志:

  1. The user under which Apache was running had no permissions to modify php_error_logfile.
  2. Error 500 occurred because of bad configuration of .htaccess, for example wrong rewrite module settings. In this situation errors are logged to Apache error_logfile.
  1. 运行 Apache 的用户没有修改php_error_log文件的权限。
  2. 错误 500 是由于错误的配置而发生的.htaccess,例如错误的重写模块设置。在这种情况下,错误会记录到 Apacheerror_log文件中。

回答by Balmipour

For Symfony projects, be sure to check files in the project'es app/logs

对于 Symfony 项目,请务必检查项目的 app/logs 中的文件

More details available on this post :
How to debug 500 Error in Symfony 2

这篇文章的更多详细信息:
如何调试 Symfony 2 中的 500 错误

Btw, other frameworks or CMS share this kind of behaviour.

顺便说一句,其他框架或 CMS 也有这种行为。

回答by Aswin Kumar

Here is another reason why errors might not be visible:

这是错误可能不可见的另一个原因:

I had the same issue. In my case, I had copied the source from a production environment. Hence the ENVIRONMENTvariable defined in index.phpwas set to 'production'. This caused error_reportingto be set to 0 (no logging). Just set it to 'development'and you should start seeing error messages in apache log.

我遇到过同样的问题。就我而言,我从生产环境复制了源代码。因此,中ENVIRONMENT定义的变量index.php设置为'production'。这导致error_reporting设置为 0(无日志记录)。只需将其设置为'development',您就应该开始在 apache 日志中看到错误消息。

Turned out the 500 was due to a semi colon missing in database config :-)

原来 500 是由于数据库配置中缺少一个分号:-)

回答by eric.itzhak

Another case which happened to me, is I did a CURL to some of my pages, and got internal server error and nothing was in the apache logs, even when I enabled all error reporting.

另一个发生在我身上的情况是,我对我的一些页面做了一个 CURL,并且得到了内部服务器错误并且 apache 日志中没有任何内容,即使我启用了所有错误报告。

My problem was that in the CURL I set curl_setopt($CR, CURLOPT_FAILONERROR, true);

我的问题是在我设置的 CURL 中 curl_setopt($CR, CURLOPT_FAILONERROR, true);

Which then didn't show me my error, though there was one, this happened because the error was on a framework level and not a PHP one, so it didn't appear in the logs.

然后没有向我显示我的错误,虽然有一个,但发生这种情况是因为错误是在框架级别而不是 PHP 级别,所以它没有出现在日志中。

回答by jcubic

If you still have 500 error and no logs you can try to execute from command line:

如果您仍然有 500 错误并且没有日志,您可以尝试从命令行执行:

php -f file.php

it will not work exactly like in a browser (from server) but if there is syntax error in your code, you will see error message in console.

它不会像在浏览器(来自服务器)中完全一样工作,但如果您的代码中有语法错误,您将在控制台中看到错误消息。

回答by John-Henry

What happened for me when this was an issue, was that the site had used too much memory, so I'm guessing that it couldn't write to an error log or displayed the error. For clarity, it was a Wordpress site that did this. Upping the memory limit on the server showed the site again.

当这是一个问题时,我发生了什么,是该站点使用了太多内存,所以我猜它无法写入错误日志或显示错误。为清楚起见,这是一个 Wordpress 网站。提高服务器上的内存限制再次显示该站点。

回答by Pavel Kenarov

Check error log inside:

检查里面的错误日志:

/usr/local/apps/apache/logs