PHP FPM returns HTTP 500 for all PHP errors

家住魔仙堡 提交于 2019-12-21 06:57:13

问题


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?


回答1:


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

 display_errors = Off

then make it on




回答2:


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.




回答3:


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.




回答4:


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.




回答5:


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

php_flag[display_errors] = on

In php.ini file:

display_errors = On



回答6:


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.




回答7:


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



来源:https://stackoverflow.com/questions/2227093/php-fpm-returns-http-500-for-all-php-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!