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

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, November 24, 2011

Follow me on Twitter as @mattiasgeniar

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.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.