Home > Article > Backend Development > nginx php blank page fastcgi_param_PHP tutorial
After installing nginx today, I found that the html page can be browsed normally, but when the php file page is opened, it is blank. I looked at the php-fpm log and the nginx log and found no problem
After searching online for a long time, I finally found the solution. I will make a note here
A saying on the Internet is that such a sentence is missing in the nginx configuration file
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
What is this sentence for? In fact, it is to define the server variables used in php, which is $_SERVER
http://wiki.nginx.org/NginxHttpFcgiModule There is such a sentence under this website
This module allows Nginx to interact with FastCGI processes and control what parameters are passed to the process.
In fact, it means that the server passes some parameters it needs to your cgi that processes php, and php must have at least the following two parameters before it can be executed
Below is an example of the minimally necessary parameters for PHP:
fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
Parameter SCRIPT_FILENAME is used by PHP for determining the name of script to execute, and QUERY_STRING contains the parameters of the request.
So when we don’t define the SCRIPT_FILENAME system variable, php cannot interpret and execute it
The definition of this variable can be written in the nginx configuration file nginx.conf, or it can be written externally and included in nginx.conf using include.