PHP FPM 对所有 PHP 错误返回 HTTP 500
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
尝试在您的 php.ini 中找到以下行:
然后将其打开
Try to find the following line in your
php.ini
:then make it on
为了发布更完整的答案,我使用了 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.我也遇到了这个问题,我在
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
inphp.ini
but it not works. Then I found thephp[display_errors]=off
inphp-fpm.conf
, and it will override the value ofphp.ini
and it works.您可以通过以下方式显示错误:转到 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 seedisplay_errors = Off
, just replaceOff
toOn
, restart php and run again.显示错误只会影响错误是否打印到输出。
如果您打开了日志错误,则日志中仍会丢失错误,除非显示关闭,这不是预期的行为。
预期的行为是,如果日志打开,则会在那里发现错误。如果显示打开,则会在屏幕/输出上发现错误。如果两者都在,则两者都会发现错误。
当前版本有一个错误,导致该功能丧失。
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.
对于 Ubuntu 12.10,在 php-fpm-pool-config 文件中:
在 php.ini 文件中:
For Ubuntu 12.10, in php-fpm-pool-config file:
In php.ini file:
如果您从 Remi 存储库安装 php72。它带有 apache| 的默认用户和组
转到您的 www.conf 文件,找到 /etc/opt/remi/php72/php-fpm.d/www.conf
并
在重新启动 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
before restart your php fpm
CENTOS REMI PHP7.2
安装缺少的 php 模块对我有用。
这解决了我的 php 脚本的持续 HTTP ERROR 500 日志。
因此,我们可以检查是否缺少应用程序正常工作所需的 php 模块。
Installing the missing php module worked for me.
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.