PHP FPM 对所有 PHP 错误返回 HTTP 500

发布于 2024-08-20 22:16:16 字数 619 浏览 2 评论 0原文

我正在使用 PHP-FPM 运行 nginx。我用于处理 php 文件的 nginx 配置如下所示:

location  ~ \.php$ {
            set $php_root /home/me/www;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $php_root$fastcgi_script_name;
            include /etc/nginx/fastcgi_params;
        }

现在,我有一个像这样的简单 php 文件:

<?php
     ech "asd"
     asd""
?>

是的,有一个明显的错误。当我尝试访问 php 文件时,我总是收到 HTTP 500 内部服务器错误,而不是跟踪语法错误。我尝试使用 error_reporting(-1); 但它仍然总是返回 HTTP 500。如何我是否可以让 PHP 打印确切的错误而不是返回通用的 HTTP 500?

I am running nginx with PHP-FPM. My nginx configuration for handling php files looks like this:

location  ~ \.php$ {
            set $php_root /home/me/www;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $php_root$fastcgi_script_name;
            include /etc/nginx/fastcgi_params;
        }

Now, I have a simple php file like this:

<?php
     ech "asd"
     asd""
?>

Yes, with an obvious error. When I try accessing the php file, instead of tracing a syntax error, I always get a HTTP 500 Internal Server Error.I tried using error_reporting(-1); but still it always returns HTTP 500. How do I get PHP to print the exact error instead of returning a generic HTTP 500?

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

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

发布评论

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

评论(8

不必你懂 2024-08-27 22:16:16

尝试在您的 php.ini 中找到以下行:

 display_errors = Off

然后将其打开

Try to find the following line in your php.ini:

 display_errors = Off

then make it on

意中人 2024-08-27 22:16:16

为了发布更完整的答案,我使用了 php.ini 的生产版本,其中 display_errors = Off。我现在所做的不是全局打开它,对于需要错误报告的文件,我在文件开头使用 ini_set('display_errors', 'On');

To post a more complete answer, I had used a production version of php.ini which has display_errors = Off. Instead of turning it on globally, what I do now is, for files which I need error reporting on, I use ini_set('display_errors', 'On'); at the beginning of the file.

放低过去 2024-08-27 22:16:16

我也遇到了这个问题,我在 php.ini 中设置了 display_errors = Off 但它不起作用。然后我在php-fpm.conf中找到了php[display_errors]=off,它会覆盖php.ini的值,并且它作品。

Also I met the problem, and I set display_errors = Off in php.ini but it not works. Then I found the php[display_errors]=off in php-fpm.conf, and it will override the value of php.ini and it works.

不知所踪 2024-08-27 22:16:16

您可以通过以下方式显示错误:转到 php.ini 并找到 display_errors,您应该看到 display_errors = Off,只需将 Off 替换为 < code>On,重启php并再次运行。

you can display errors by this way: go to php.ini and find display_errors, you should see display_errors = Off, just replace Off to On, restart php and run again.

愁以何悠 2024-08-27 22:16:16

显示错误只会影响错误是否打印到输出。

如果您打开了日志错误,则日志中仍会丢失错误,除非显示关闭,这不是预期的行为。

预期的行为是,如果日志打开,则会在那里发现错误。如果显示打开,则会在屏幕/输出上发现错误。如果两者都在,则两者都会发现错误。

当前版本有一个错误,导致该功能丧失。

Display errors will only affect the fact that the errors are printed to output or not.

If you have log errors turned on, the errors will still be missing from log unless display is off, which isn't the expected behavior.

The expected behavior is if log is on, errors are found there. If display is on, errors are found on screen/output. If both are on erros are found on both.

Current versions have a bug that forfeits that.

攀登最高峰 2024-08-27 22:16:16

对于 Ubuntu 12.10,在 php-fpm-pool-config 文件中:

php_flag[display_errors] = on

在 php.ini 文件中:

display_errors = On

For Ubuntu 12.10, in php-fpm-pool-config file:

php_flag[display_errors] = on

In php.ini file:

display_errors = On
孤独难免 2024-08-27 22:16:16

如果您从 Remi 存储库安装 php72。它带有 apache| 的默认用户和组

转到您的 www.conf 文件,找到 /etc/opt/remi/php72/php-fpm.d/www.conf

user=nginx
group=nginx

在重新启动 php fpm

systemctl restart php72-php-fpm

CENTOS REMI PHP7.2之前进行更改

If you install from Remi repo php72. It come default user and group with apache|

go to your www.conf file it locate /etc/opt/remi/php72/php-fpm.d/www.conf

and change

user=nginx
group=nginx

before restart your php fpm

systemctl restart php72-php-fpm

CENTOS REMI PHP7.2

清风疏影 2024-08-27 22:16:16

安装缺少的 php 模块对我有用。

sudo apt install php7.2-curl
sudo systemctl restart php7.2-fpm

这解决了我的 php 脚本的持续 HTTP ERROR 500 日志。

因此,我们可以检查是否缺少应用程序正常工作所需的 php 模块。

Installing the missing php module worked for me.

sudo apt install php7.2-curl
sudo systemctl restart php7.2-fpm

This solved my log lasting HTTP ERROR 500 of my php script.

Thus one can check if there are any missing php modules that the application may need to work properly.

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