How to Install PHP-FPM for Nginx!

Recently, I’ve switched some of my web servers that handle large file downloads from spawn-cgi to PHP-FPM.  The result is that I can handle more large files with more PHP-CGI processes while my site still loads well even if there’s many concurrent downloads going on.

I am still experimenting with PHP-FPM but it seems like a pretty good way to go as far as handling the PHP-CGI processes.

To do this, you will need to install EPEL & CentALT repositories:

rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-3.noarch.rpm

rpm -Uvh http://centos.alt.ru/repository/centos/5/x86_64/centalt-release-5-3.noarch.rpm

Then do:

yum install php-fpm

to install php-fpm.

Edit the file /etc/php-fpm.conf

and my suggested setting changes:

<value name=”user”>apache</value>
<value name=”group”>apache</value>

The max_children is set to 1 as default, set it to something like 50, this really is the cool part about php-fpm.

<value name=”max_children”>50</value>

 

PHP-FPM doesn’t allow for root user and group so I set it to apache.  You will also need to set your web directories to apache user and group by doing:

chown apache:apache /mywebdirectory

Start the PHP-FPM by doing:

/sbin/service php-fpm start

If you get some kind of session errors, simply erase all the session files where the error shows.

For CentOS, you can do:

chkconfig php-fpm on

so it will start whenever your webserver is rebooted.

If you have been using fastcgi, make sure to do:

chkconfig fastcgi off

so it doesn’t interfere.

 

Share

Recommended Nginx Hacks



This entry was posted in Nginx Hacks, Web Server Hacks and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Related News and Resources