Getting Fatal Errors in Nginx to Be Shown in the Browser

10,978

Solution 1

In your PHP-FPM Pool config uncomment

line 463 php_flag[display_errors] = off

and change it to

php_flag[display_errors] = on

and don't forget to restart php-fpm

Solution 2

I figured our setting display_errors was not enough to display the errors with nginx.

The final trick for me to solve this was to turn off fastcgi_intercept_errors:

fastcgi_intercept_errors off;

Usually this is on by default, for example in fastcgi_params.

Share:
10,978

Related videos on Youtube

mhdnp1234
Author by

mhdnp1234

Updated on September 18, 2022

Comments

  • mhdnp1234
    mhdnp1234 almost 2 years

    While developing I'm getting blank pages in my browser whenever I create a fatal error in PHP with a typo or just my bad programming ;). It's super annoying for me to have to view the raw nginx error log file to see the fatal errors and find the line numbers where they are. I can't seem to find how to make nginx display PHP fatal errors in the browser. Here is the relevant part of my nginx config:

    location @fpm {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_NAME index.php;
        fastcgi_param SCRIPT_FILENAME $document_root/index.php;
        fastcgi_param PATH_INFO $path_info;
    }
    

    Here's an example error that shows up in my error log and then results in a blank browser page:

    2014/01/04 14:53:52 [error] 20082#0: *403 FastCGI sent in stderr:
    "PHP message: PHP Fatal error:  Cannot redeclare class ClassName in FilePath on line 356"
    while reading response header from upstream, client: 192.168.1.10,
    server: servername, request: "GET URLPATH HTTP/1.1",
    upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "host",
    referrer: "referer"
    

    Here is my PHP info:

    enter image description here

    Here is my PHP-FPM conf:

    http://pastebin.com/QkCTbBYj

    And my PHP-FPM pool conf:

    http://pastebin.com/TZfZ8d7G

    And my PHP-FPM php.ini:

    http://pastebin.com/RsXRxduf

    I would love if anyone could shed some light on what I could do to get these errors to show up!