PHP FPM 为所有 PHP 错误返回 HTTP 500
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2227093/
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
PHP FPM returns HTTP 500 for all PHP errors
提问by ErJab
I am running nginx with PHP-FPM. My nginx configuration for handling php files looks like this:
我正在使用 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;
}
Now, I have a simple php file like this:
现在,我有一个简单的 php 文件,如下所示:
<?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?
是的,有一个明显的错误。当我尝试访问 php 文件时,而不是跟踪语法错误,我总是得到一个 HTTP 500 内部服务器错误。我尝试使用error_reporting(-1);但它仍然总是返回 HTTP 500。如何让 PHP 打印确切的错误而不是返回一个通用 HTTP 500?
回答by Young
Try to find the following line in your php.ini:
尝试在您的php.ini:
display_errors = Off
then make it on
然后让它
回答by ErJab
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。我现在所做的不是全局打开它,而是对于需要错误报告的文件,我ini_set('display_errors', 'On');在文件的开头使用。
回答by yaronli
Also I met the problem, and I set display_errors = Offin php.inibut it not works. Then I found the php[display_errors]=offin php-fpm.conf, and it will override the value of php.iniand it works.
我也遇到了这个问题,我设置display_errors = Off了php.ini但它不起作用。然后我找到了php[display_errors]=offin php-fpm.conf,它会覆盖 的值php.ini并且它可以工作。
回答by Luis Ferro
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.
当前版本有一个错误,会失去它。
回答by user2009092
For Ubuntu 12.10, in php-fpm-pool-config file:
对于 Ubuntu 12.10,在 php-fpm-pool-config 文件中:
php_flag[display_errors] = on
In php.ini file:
在 php.ini 文件中:
display_errors = On
回答by Bách Nguy?n
you can display errors by this way: go to php.ini and find display_errors, you should see display_errors = Off, just replace Offto On, restart php and run again.
您可以通过这种方式显示错误:转到 php.ini 并找到display_errors,您应该看到display_errors = Off,只需替换Off为On,重新启动 php 并再次运行。
回答by Turan Zamanl?
If you install from Remi repo php72. It come default user and group with apache|
如果您从 Remi repo php72 安装。它带有apache的默认用户和组|
go to your www.conf file it locate /etc/opt/remi/php72/php-fpm.d/www.conf
转到您的 www.conf 文件,找到 /etc/opt/remi/php72/php-fpm.d/www.conf
and change
和改变
user=nginx
group=nginx
before restart your php fpm
在重启你的 php fpm 之前
systemctl restart php72-php-fpm
CENTOS REMI PHP7.2
CentOS REMI PHP7.2

