24

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?

3
  • If the file didn't have the error, would you get the correct response code (HTTP 200 OK)?
    – echo
    Feb 9, 2010 at 6:01
  • Yes, I get a HTTP 200 OK if the file doesn't have an error.
    – ErJab
    Feb 9, 2010 at 6:09
  • 1
    It's generally better to log errors than display them. Jul 1, 2012 at 16:27

7 Answers 7

43

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

 display_errors = Off

then make it on

5
  • Thank you! I use a production version of php.ini in which display_errors is Off.
    – ErJab
    Feb 9, 2010 at 8:14
  • 1
    I was using a PHP-Fastcgi script so when I changed to php-fpm recently. I didn't notice that the php.ini changed to FPM's version. Their version has dispaly_errors = Off so all my pages started coming up blank when an error happened!
    – Xeoncross
    Aug 22, 2011 at 20:00
  • 7
    do not forget reset php-fpm after that. (sudo service php-fpm restart)
    – alioygur
    Apr 25, 2012 at 8:11
  • 1
    Also don't forget to change error_level to E_ALL, and if you don't have php-fpm as a service to restart it just do sudo /etc/init.d/php5-fpm restart
    – srcspider
    Mar 26, 2013 at 7:52
  • Also check your PHP version and the version mentioned in fastcgi.conf file.
    – Rakib
    Feb 26, 2022 at 10:15
9

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.

2
  • The problem with that is that according to the documentation it won't work if a Fatal Error happens.
    – srcspider
    Mar 26, 2013 at 7:41
  • @srcspider Not really huh? Even fatal errors are indicated. All you have to do is just making sure that you put this ini_set('display_errors', 'On') at the very top of the scope you are considering. Sep 18, 2017 at 7:56
7

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.

1
  • 1
    php.ini has nothing to do with configurations, if you are using php-fpm in which case you will need to modify the php-fpm.conf. Sep 18, 2017 at 7:57
1

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.

1
  • Do you know a bug ticket in php.net that tracks this bug? Can you link to it?
    – Sven
    Oct 4, 2012 at 19:35
1

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

php_flag[display_errors] = on

In php.ini file:

display_errors = On
1

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.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.