Thursday, February 10, 2011

how to install and configure Nginx + PHP FPM

Building PHP with FPM Support,

# ./configure --enable-fpm --prefix=/opt/phpfpm

Make
Make Install

image

then you can run the php-fpm by run “php-fpm ”, php-fpm is located in the sbin dir
if you get error like unable to find the conf file like following ,

image

just rename /opt/phpfmp/etc/php-fpm.conf.default as php-fpm.conf , change the min/max/startserver value
image
Also copy the /tmp/php-x/php.ini-production to /opt/phpfpm/php.ini
run netstat –an |grep 9000
image

Now install nginx following install and config Nginx/PhP fastcgi on Centos
change the nginx.conf to include fpm for php backend proxy processing. just uncomment the default conf settings,

location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME /opt/nginx/html/$fastcgi_script_name;
        include        fastcgi_params;
    }

restart nginx –s restart

then create one info.php and put it under /opt/ngnix/html

<?php phpinfo();?>

Now, you can access http://localhost/info.php, you will get php info page.

image

Here is the raw traffic between Nginx and PhpFPM
image

If you get 404 error no matter how, check the nginx.conf point to the absolute path of the script

fastcgi_param  SCRIPT_FILENAME /opt/nginx/html/$fastcgi_script_name;

No comments:

 
Locations of visitors to this page