内部错误 500 Apache,但日志中没有任何内容?

发布于 2024-10-12 09:53:14 字数 147 浏览 10 评论 0原文

当我尝试向应用程序中的特定地址发出 HTTP POST 时,出现 500 个内部服务器错误。我查看了虚拟主机文件中指定的自定义日志目录中的服务器日志,但错误没有显示在那里,因此调试这是一件很痛苦的事情。

如何让 Apache 将内部 500 错误记录到错误日志中?

I'm getting 500 Internal Server errors when I try to make an HTTP POST to a specific address in my app. I've looked into the server logs in the custom log directory specified in the virtual hosts file, but the error doesn't show up there so debugging this has been a pain in the ass.

How do I cause Apache to log Internal 500 errors into the error log?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

英雄似剑 2024-10-19 09:53:14

这是 2013 年的一个古老答案,当时 PHP 还很新鲜,安全性还不是问题:

将来,像这样将错误转储到屏幕上会存在安全风险。您最好不要在任何生产环境中执行此操作。

为什么 500 内部服务器错误没有记录到您的 apache 错误日志中?

导致 500 内部服务器错误的错误来自 PHP 模块。默认情况下,PHP 不记录这些错误。原因是您希望 Web 请求尽可能快地进行,而将错误记录到攻击者可以观察到的屏幕上会存在安全隐患。

这些启用内部服务器错误日志记录的说明适用于带有 PHP 5.3.10Apache/2.2.22Ubuntu 12.10

确保 PHP 日志记录已打开:

  1. 找到您的 php.ini 文件:

    el@apollo:~$ 定位 php.ini
    /etc/php5/apache2/php.ini
    
  2. 以 root 身份编辑该文件:

    sudo vi /etc/php5/apache2/php.ini
    
  3. 在 php.ini 中找到此行:

    display_errors = 关闭
    
  4. 将上面的行更改为:

    display_errors = 开
    
  5. 在文件下方,您将看到以下内容:

    <前><代码>;display_startup_errors
    ;默认值:关闭
    ;开发价值:开
    ;产值:关闭

    ;错误报告
    ;默认值:E_ALL & ~E_注意
    ;开发价值:E_ALL | E_STRICT
    ;生产值:E_ALL & ~E_已弃用

  6. 分号是注释,这意味着这些行不会生效。更改这些行,使它们看起来像这样:

    display_startup_errors = 开
    ;默认值:关闭
    ;开发价值:开
    ;产值:关闭
    
    错误报告 = E_ALL
    ;默认值:E_ALL & ~E_通知
    ;开发价值:E_ALL | E_STRICT
    ;生产值:E_ALL & ~E_已弃用
    

    这向 PHP 传达的是我们想要记录所有这些错误。警告,这会对性能造成很大影响,因此您不希望在生产中启用此功能,因为日志记录需要工作,而工作需要时间,时间会花钱。

  7. 重新启动 PHP 和 Apache 应该会应用更改。

  8. 再次执行导致 500 Internal Server 错误的操作,并检查日志:

    tail -f /var/log/apache2/error.log
    
  9. 您应该在末尾看到 500 错误,如下所示:

    [Wed Dec 11 01:00:40 2013] [错误] [客户端 192.168.11.11] PHP 致命错误:  
    调用 /yourproject/ 中未定义的函数 Foobar\\byob\\penguin\\alert()
    your_src/symfony/Controller/MessedUpController.php 第 249 行
    

This is an Ancient answer from 2013, back when PHP was new and security wasn't an issue:

Here in the future it's a security risk to dump errors to screen like this. You better not be doing this in any production setting.

Why are the 500 Internal Server Errors not being logged into your apache error logs?

The errors that cause your 500 Internal Server Error are coming from a PHP module. By default, PHP does NOT log these errors. Reason being you want web requests go as fast as physically possible and it's a security hazard to log errors to screen where attackers can observe them.

These instructions to enable Internal Server Error Logging are for Ubuntu 12.10 with PHP 5.3.10 and Apache/2.2.22.

Make sure PHP logging is turned on:

  1. Locate your php.ini file:

    el@apollo:~$ locate php.ini
    /etc/php5/apache2/php.ini
    
  2. Edit that file as root:

    sudo vi /etc/php5/apache2/php.ini
    
  3. Find this line in php.ini:

    display_errors = Off
    
  4. Change the above line to this:

    display_errors = On
    
  5. Lower down in the file you'll see this:

    ;display_startup_errors
    ;   Default Value: Off
    ;   Development Value: On
    ;   Production Value: Off
    
    ;error_reporting
    ;   Default Value: E_ALL & ~E_NOTICE
    ;   Development Value: E_ALL | E_STRICT
    ;   Production Value: E_ALL & ~E_DEPRECATED
    
  6. The semicolons are comments, that means the lines don't take effect. Change those lines so they look like this:

    display_startup_errors = On
    ;   Default Value: Off
    ;   Development Value: On
    ;   Production Value: Off
    
    error_reporting = E_ALL
    ;   Default Value: E_ALL & ~E_NOTICE
    ;   Development Value: E_ALL | E_STRICT
    ;   Production Value: E_ALL & ~E_DEPRECATED
    

    What this communicates to PHP is that we want to log all these errors. Warning, there will be a large performance hit, so you don't want this enabled on production because logging takes work and work takes time, time costs money.

  7. Restarting PHP and Apache should apply the change.

  8. Do what you did to cause the 500 Internal Server error again, and check the log:

    tail -f /var/log/apache2/error.log
    
  9. You should see the 500 error at the end, something like this:

    [Wed Dec 11 01:00:40 2013] [error] [client 192.168.11.11] PHP Fatal error:  
    Call to undefined function Foobar\\byob\\penguin\\alert() in /yourproject/
    your_src/symfony/Controller/MessedUpController.php on line 249
    
夏夜暖风 2024-10-19 09:53:14

我刚刚遇到了这个问题,这是由于我的 .htaccess 文件中的 mod_authnz_ldap 配置错误造成的。绝对没有记录任何内容,但我不断收到 500 错误。

如果遇到这个特定问题,您可以更改 mod_authnz_ldap 的日志级别,如下所示:

LogLevel warn authnz_ldap_module:debug

这将为 mod_authnz_ldap 使用调试日志级别,但对其他所有内容发出警告(https://httpd.apache.org/docs/2.4/en/mod/core.html#loglevel)。

I just ran into this and it was due to a mod_authnz_ldap misconfiguration in my .htaccess file. Absolutely nothing was being logged, but I kept getting a 500 error.

If you run into this particular issue, you can change the log level of mod_authnz_ldap like so:

LogLevel warn authnz_ldap_module:debug

That will use a log level of debug for mod_authnz_ldap but warn for everything else (https://httpd.apache.org/docs/2.4/en/mod/core.html#loglevel).

熟人话多 2024-10-19 09:53:14

检查您的 php 错误日志,它可能是与 apache 错误日志不同的文件。

通过转到 phpinfo() 找到它并检查 error_log 属性。
如果没有设置。设置它: https://stackoverflow.com/a/12835262/445131

也许你的 post_max_size 对于你的来说太小了正在尝试发帖,或者其他最大内存设置之一太低。

Check your php error log which might be a separate file from your apache error log.

Find it by going to phpinfo() and check for error_log attribute.
If it is not set. Set it: https://stackoverflow.com/a/12835262/445131

Maybe your post_max_size is too small for what you're trying to post, or one of the other max memory settings is too low.

挽清梦 2024-10-19 09:53:14

如果日志文件中没有显示您的内部服务器错误信息,您可能需要重新启动 Apache 服务

我发现 Apache 2.4(至少在 Windows 平台上)倾向于顽固地拒绝刷新日志文件,相反,记录的数据会在内存中保留相当长的一段时间。从性能的角度来看这是一个好主意,但在开发时可能会造成混乱。

If your Internal Server Error information doesn't show up in log files, you probably need to restart the Apache service.

I've found that Apache 2.4 (at least on Windows platform) tends to stubbornly refuse to flush log files—instead, logged data remains in memory for quite a while. It's a good idea from the performance point of view but it can be confusing when developing.

满意归宿 2024-10-19 09:53:14

请注意:原始发帖者并未专门询问有关 PHP 的问题。所有以 php 为中心的答案都做出了与实际问题无关的大量假设。

与脚本错误日志相反,默认错误日志通常具有(更多)特定错误。通常会出现权限被拒绝甚至找不到解释器的情况。

这意味着错误几乎总是出在你的脚本上。例如,您上传了一个 perl 脚本但没有授予它执行权限?或者它可能在 Linux 环境中被损坏,如果您在 Windows 中编写脚本,然后将其上传到服务器而不转换行结尾,您将收到此错误。

在perl中,如果你忘记了,

print "content-type: text/html\r\n\r\n";

你会得到这个错误

,原因有很多。因此,请首先检查您的错误日志,然后提供更多信息。

默认错误日志通常位于 /var/log/httpd/error_log/var/log/apache2/error.log 中。

您查看默认错误日志(如上所述)的原因是因为错误并不总是发布到虚拟主机中定义的自定义错误日志中。

假设是 linux 而不是 perl

Please Note: The original poster was not specifically asking about PHP. All the php centric answers make large assumptions not relevant to the actual question.

The default error log as opposed to the scripts error logs usually has the (more) specific error. often it will be permissions denied or even an interpreter that can't be found.

This means the fault almost always lies with your script. e.g you uploaded a perl script but didnt give it execute permissions? or perhaps it was corrupted in a linux environment if you write the script in windows and then upload it to the server without the line endings being converted you will get this error.

in perl if you forget

print "content-type: text/html\r\n\r\n";

you will get this error

There are many reasons for it. so please first check your error log and then provide some more information.

The default error log is often in /var/log/httpd/error_log or /var/log/apache2/error.log.

The reason you look at the default error logs (as indicated above) is because errors don't always get posted into the custom error log as defined in the virtual host.

Assumes linux and not necessarily perl

我早已燃尽 2024-10-19 09:53:14

@eric-leschinski 的答案是正确的。

但还有另一种情况,如果您的服务器 API 是 FPM/FastCGI(Centos 8 上默认,或者您可以检查使用 phpinfo() 函数)

在这种情况下:

  1. 运行 phpinfo()在 php 文件中;
  2. 寻找 加载的配置文件 参数来查看 PHP 的配置文件在哪里。
  3. 像 @eric-leschinski 的答案一样编辑配置文件。
  4. 检查服务器 API 参数。
    如果您的服务器仅使用 apache 句柄 API ->重新启动阿帕奇。
    如果您的服务器使用 php-fpm 您必须重新启动 php-fpm 服务

    <块引用>

    systemctl 重新启动 php-fpm

    检查 php-fpm 日志文件夹中的日志文件。例如 /var/log/php-fpm/www-error.log

The answers by @eric-leschinski is correct.

But there is another case if your Server API is FPM/FastCGI (Default on Centos 8 or you can check use phpinfo() function)

In this case:

  1. Run phpinfo() in a php file;
  2. Looking for Loaded Configuration File param to see where is config file for your PHP.
  3. Edit config file like @eric-leschinski 's answer.
  4. Check Server API param.
    If your server only use apache handle API -> restart apache.
    If your server use php-fpm you must restart php-fpm service

    systemctl restart php-fpm

    Check the log file in php-fpm log folder. eg /var/log/php-fpm/www-error.log

只是我以为 2024-10-19 09:53:14

请检查您是否在代码中的某个位置禁用了错误报告。

我的代码中有一个地方禁用了它,所以我在它后面添加了调试代码:

require_once("inc/req.php");   <-- Error reporting is disabled here

// overwrite it
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

Please check if you are disable error reporting somewhere in your code.

There was a place in my code where I have disabled it, so I added the debug code after it:

require_once("inc/req.php");   <-- Error reporting is disabled here

// overwrite it
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
像极了他 2024-10-19 09:53:14

HttpProtocolOptions Unsafe 添加到您的 apache 配置文件中并重新启动 apache 服务器。它显示错误详细信息。

Add HttpProtocolOptions Unsafe to your apache config file and restart the apache server. It shows the error details.

左秋 2024-10-19 09:53:14

就我而言,它是 httpd.conf 中的 ErrorLog 指令。只是在我放弃后无意中注意到了它。决定分享这个发现)
现在我知道在哪里可以找到 500 错误。

In my case it was the ErrorLog directive in httpd.conf. Just accidently noticed it already after I gave up. Decided to share the discovery )
Now I know where to find the 500-errors.

﹏雨一样淡蓝的深情 2024-10-19 09:53:14

检查您正在运行的 php 版本是否与您的代码库匹配。例如,您的本地环境可能正在运行 php 5.4(并且运行良好),并且您可能正在安装了 php 5.3 的新计算机上测试代码。如果您使用 5.4 语法,例如 array() 的 [],那么您将遇到上面描述的情况。

Check that the version of php you're running matches your codebase. For example, your local environment may be running php 5.4 (and things run fine) and maybe you're testing your code on a new machine that has php 5.3 installed. If you are using 5.4 syntax such as [] for array() then you'll get the situation you described above.

随遇而安 2024-10-19 09:53:14

尝试访问静态文件。如果这也不起作用那么
转到从根“/”或“c:\”到文件目录的所有目录,并检查它们是否包含“.htaccess”文件。

我曾经在“c:\”中留下了一个文件,它产生了最奇怪的结果。

Try accessing a static file. If this is not working either then
go to all directories from the root "/" or "c:\" to the directory of your file and check if they contain ".htaccess" files.

I once left a file in "c:\" and it had the most strange results.

妄断弥空 2024-10-19 09:53:14

当我在第 1 列以外的地方使用 # 注释符号时,就会出现此错误配置消息(请记住,Apache 是旧软件,其中列号和空格有时可能很重要)。

Options -Indexes # 从不显示文件夹索引

This misconfiguration message happened for me when I used the # comment symbol in other than column 1 (remember, Apache is old software where column numbers and whitespace can sometimes be significant).

Options -Indexes # Never show folder indices

探春 2024-10-19 09:53:14

添加 ScriptLog logs/cgi_log[ 1]到你的服务器配置文件,然后你会得到Python或Bash语法错误打印到它(当然还有所有其他错误 - 除了PHP错误,这些错误是由不同的控制指示)。

Add ScriptLog logs/cgi_log[1] to your server configuration file, then you'll get Python or Bash syntax errors printed to it (and all other errors too, of course - except for PHP errors, these are controlled by a different directive).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文