Nginx returning blank white page on PHP parsed with FastCGI or PHP-FPM

I’ve just spent a while debugging this, was tricky’er than I thought. I had a (in theory) correct Nginx & PHP-FPM config, but whenever a PHP script was being parsed via php-fpm I could only get a blank white page – nothing more.

Turns out I missed a few vital parts of my FastCGI config.

So, for starters, when you get this: check all your access and errors logs. If your blank white page is returning a “200 OK” HTTP status code, changes are it’s being passed to PHP-FPM perfectly but it just doesn’t know how to parse it because some parameters are missing.

Here’s what I eventually went for that worked.

upstream backend_php {
    server 127.0.0.1:9000;
}

-snip-

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_index   index.php;
    fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    #fastcgi_param  PATH_INFO $fastcgi_script_name;
    include         fastcgi_params;

    if (-f $request_filename) {
        # Only throw it at PHP-FPM if the file exists (prevents some PHP exploits)
        fastcgi_pass    backend_php;     # The upstream determined above
    }
}

The important bits are the “upstream” selector and the fastcgi_params. Get those in that exact same way, and you should be good to go.

For more info on setting up Nginx 1.0 with PHP-FPM 5.3, check out the guide I wrote a while back.