27

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)? Commented Feb 9, 2010 at 6:01
  • Yes, I get a HTTP 200 OK if the file doesn't have an error. Commented Feb 9, 2010 at 6:09
  • 1
    It's generally better to log errors than display them. Commented Jul 1, 2012 at 16:27

8 Answers 8

44

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

 display_errors = Off

then make it on

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you! I use a production version of php.ini in which display_errors is Off.
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!
do not forget reset php-fpm after that. (sudo service php-fpm restart)
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
Also check your PHP version and the version mentioned in fastcgi.conf file.
8

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 Comments

The problem with that is that according to the documentation it won't work if a Fatal Error happens.
@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.
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 Comment

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.
2

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.

Comments

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 Comment

Do you know a bug ticket in php.net that tracks this bug? Can you link to it?
1

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

php_flag[display_errors] = on

In php.ini file:

display_errors = On

Comments

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

Comments

-2

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.

1 Comment

You are doing it upside down. You have to check the logs first, as already suggested in many answers, get the actual error message, and only then go to install any module, fix the configuration error, or resolve whatever else issue indicated by the actual error message

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.