If you have managed to configure and start PHP-FPM correctly, you are ready to tweak your Nginx configuration file to establish the connection between both parties. The following server block is a simple, valid template on which you can base your own website configuration:
server { server_name .website.com; # server name, accepting www listen 80; # listen on port 80 root /home/website/www; # our root document path index index.php; # default request filename: index.php location ~* .php$ { # for requests ending with .php # specify the listening address and port that you configured previously fastcgi_pass 127.0.0.1:9000; # the document path to be passed to PHP-FPM fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # the script filename to be passed to PHP-FPM fastcgi_param PATH_INFO $fastcgi_script_name; # include other FastCGI related configuration settings include fastcgi_params; } }
After saving the configuration file, reload Nginx using one of the following commands:
/usr/local/nginx/sbin/nginx -s reload
Or:
service nginx reload
Create a simple script at the root of your website to make sure PHP is being correctly interpreted:
[user@local ~]# echo "<?php phpinfo(); ?>" >/home/website/www/index.php
Fire up your favorite web browser and load http://localhost/ (or your website URL). You should see something similar to the following screenshot, which is the PHP server information page:
Note that you may run into the occasional 403 forbidden HTTP error, if the file and directory access permissions are not properly configured. If that is the case, make sure that you specified the correct user and group in the php-fpm.conf file and that the directory and files are readable by PHP.