Posted by: Hartoto | 01/15/2014

Instalasi PHP-FPM + FastCGI di CentOS Apache2 (httpd)

Bagi yang belum paham FastCGI, kelebihan, dan perbedaannya dengan Mod_PHP, suPHP silakan buka dulu link ini . Kali ini saya akan menjelaskan cara menginstal PHP-FPM di distro kesayangan saya, CentOS.

1. Install Apache , PHP-FPM and FastCGI

  • yum install httpd mod_fastcgi php-fpm

2. Configure PHP-FPM to start at boot

  • chkconfig –levels 235 php-fpm on
  • /etc/init.d/php-fpm start

3. Configure Apache to use mod_fastcgi

  • sed -i ‘s/FastCgiWrapper On/FastCgiWrapper Off/g’ /etc/httpd/conf.d/fastcgi.conf
  • echo -e “<IfModule mod_fastcgi.c>\nDirectoryIndex index.html index.shtml index.cgi index.php\nAddHandler php5-fcgi .php\nAction php5-fcgi /php5-fcgi\nAlias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi\nFastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization\n</IfModule>” >> /etc/httpd/conf.d/fastcgi.conf
  • mkdir /usr/lib/cgi-bin/

4. Fix Permissions

  • chown -R apache:apache /var/run/mod_fastcgi

5. Disable mod_php

  • sed -i ‘s/LoadModule php5_module/\#LoadModule php5_module/g;s/AddHandler/\#AddHandler/g;s/AddType/\#AddType/g;’ /etc/httpd/conf.d/php.conf

6. optimise php-fpm

  • sed -i ‘s/;listen.backlog = -1/listen.backlog = 1000/’ /etc/php-fpm.d/www.conf
  • sed -i ‘s/pm.max_children = 50/pm.max_children = 512/’ /etc/php-fpm.d/www.conf
  • sed -i ‘s/pm.start_servers = 5/pm.start_servers = 16/’ /etc/php-fpm.d/www.conf
  • sed -i ‘s/pm.min_spare_servers = 5/pm.min_spare_servers = 10/’ /etc/php-fpm.d/www.conf
  • sed -i ‘s/pm.max_spare_servers = 35/pm.max_spare_servers = 64/’ /etc/php-fpm.d/www.conf
  • sed -i ‘s/;pm.max_requests = 500/pm.max_requests = 5000/’ /etc/php-fpm.d/www.conf
  • sed -i ‘s/;rlimit_files = 1024/rlimit_files = 102400/’ /etc/php-fpm.d/www.conf

7. Restart Apache

  • /etc/init.d/httpd restart atau service httpd restart

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: