Fixed: Nginx showing blank PHP pages with FastCGI or PHP-FPM

Every time when I configure a new Website or blog with Nginx and PHP-FPM, I missed this setting and then spend a lot of time searching for this issue on google. And every time I found the same issue which I will cover in this article.

Before applying this fix you should check your access and error logs of Nginx. If you did not get any error in the error log and get HTTP status 200/OK in the access log. But still, you get the blank pages on all PHP pages then this fix will solve your problem.

So as always we will do it in few simple steps. At the very first step lets see our site config for WordPress blogs.

Step 1: Location block config for all PHP files

Below is the location block I used for WordPress Blogs.

location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_pass unix:/run/php/php7.3-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
}

Here I include the fastcgi_params from ngx_http_fastcgi_module of Nginx. But I forgot to add the next line in the required file.

Step 2: Add the fastcgi_param in the config file

We just have to open the /etc/nginx/fastcgi_params file and add the below line at the end of the file.

fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;

OR you can directly pass this line by the below command.

echo "fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;" >> /etc/nginx/fastcgi_params

Now restart the PHP-FPM service and Nginx Service using the below commands.

systemctl restart php7.3-fpm
systemctl restart nginx

Note: if you have a different version of PHP-FPM then you have to use that in place of 7.3

As states on Nginx Docs, the parameter should be passed to the FastCGI server. After applying this fix your PHP pages should work. If not then you probably had another issue. You can ask in the comment if your site still not working I will try to resolve the issue for you.

3 thoughts on “Fixed: Nginx showing blank PHP pages with FastCGI or PHP-FPM”

  1. Just change the line of location block:
    include fastcgi_params;
    to
    include fastcgi.conf;

    And you’re good. No need to change fastcgi_params

    Reply

Leave a Comment