CentOS 6, httpd-2.2 and php-fpm

When your webserver is receiving a lot of traffic and began slow your website down, you might be consider to switch mod_php with php-fpm.

  • First get mod_fastcgi from rpmforge
  • Install php-fpm
1# yum install php-fpm
  • Configure php-fpm
1# vi /etc/php-fpm.d/www.conf
2listen = /var/run/php5-fpm.sock
3;listen = 127.0.0.1:9000
4listen.backlog = 1024
5listen.owner = apache
6listen.group = apache
7listen.mode = 0666
8 
9user = apache
10group = apache
11 
12pm = ondemand
13pm.max_children = 75
14pm.start_servers = 10
15pm.min_spare_servers = 5
16pm.max_spare_servers = 20
17pm.process_idle_timeout = 10s
18pm.max_requests = 500
  • Rename mod.php to mod.php.bak
1# cd /etc/httpd/conf.d/
2# mv php.conf php.conf.bak

that will disabled mod_php.

  • Configure mod_fastcgi in /etc/httpd/conf.d/fastcgi.conf. add these lines at the end of file.
1# vi /etc/httpd/conf.d/fastcgi.conf
2...
3FastCgiWrapper Off
4FastCgiConfig -idle-timeout 20 -maxClassProcesses 1
5...
6DirectoryIndex index.php
7AddHandler php-fcgi .php
8Action php-fcgi /php-fcgi
9Alias /php-fcgi /cgi-bin-php.fcgi
10FastCgiExternalServer /cgi-bin-php.fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization
  • Start php-fpm and restart httpd service.
1# service php-fpm start
2# service httpd restart

that’s it.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

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