{"id":392,"date":"2013-11-08T19:19:42","date_gmt":"2013-11-08T19:19:42","guid":{"rendered":"http:\/\/blog.shineservers.com\/?p=392"},"modified":"2013-11-08T19:19:42","modified_gmt":"2013-11-08T19:19:42","slug":"install-configure-optimise-php5-php5-fpm","status":"publish","type":"post","link":"https:\/\/www.shineservers.com\/2013\/11\/08\/install-configure-optimise-php5-php5-fpm\/","title":{"rendered":"Install, Configure &#038; Optimise PHP5 with PHP5-FPM"},"content":{"rendered":"<blockquote><p>PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites.<br \/>\nSource :\u00a0<a title=\"PHP FPM\" href=\"http:\/\/php-fpm.org\/\" rel=\"external\">PHP-FPM Website<\/a><\/p><\/blockquote>\n<p>PHP-FPM is far better than the standard mod_php implementation of PHP and also easier to implement that spawn-fcgi. PHP-FPM works like an application that loads and kills PHP instances as needed. Of all the benefits that it offers, reduced memory usage is the most attractive one.<\/p>\n<h2>Step 1 : Add the Dotdeb repository<\/h2>\n<p>You can skip this step if you have already added the Dotdeb repository while\u00a0installing NGINX\u00a0on your Debian Server. The version of PHP and PHP-FPM in the Dotdeb repository is up-to-date and stable. We need to grab the latest version of PHP to benefit from all new updates and bug fixes.<\/p>\n<h2>Step 2 : Installing PHP and PHP-FPM<\/h2>\n<p>The following command will do it all for you. I have included some popular PHP modules. You can choose and install the modules that you require.<\/p>\n<div>\n<div id=\"highlighter_217382\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<\/td>\n<td>\n<div>\n<div><code>sudo<\/code> <code>apt-get\u00a0<\/code><code>install<\/code> <code>php5-cgi php5-cli php5-common php5-curl php5-dev php5-fpm php5-gd php5-idn php5-imagick php5-imap php5-json php5-mcrypt php5-memcache php5-mhash php5-ming php5-mysql php5-<\/code><code>ps<\/code> <code>php5-pspell php5-recode php5-snmp php5-sqlite php5-suhosin php5-tidy php5-xcache php5-xmlrpc php5-xsl php-pear php-soap<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>This command will install PHP-FPM and auto start the service. PHP-FPM will get added to the startup.<\/p>\n<h2>Step 3 : Configuring and Optimising PHP<\/h2>\n<p>As you will be using PHP-FPM to process PHP scripts, edit the php.ini file that can be found at \/etc\/php5\/fpm\/php.ini. There are a lot of PHP settings that you can configure to optimise PHP for performance, speed and security. The following three are a good starting point.<\/p>\n<div>\n<div id=\"highlighter_429988\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<\/td>\n<td>\n<div>\n<div><code>memory_limit = 64M<\/code><\/div>\n<div><code>expose_php = Off<\/code><\/div>\n<div><code>display_errors = Off<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h2>Step 4 : Configuring and Optimising PHP-FPM<\/h2>\n<p>Remember, we are setting up a low-end (256MB) web server on Shine Servers. We need to conserve as much memory as possible. Edit the file \/etc\/php5\/fpm\/pool.d\/www.conf<\/p>\n<div>\n<div id=\"highlighter_149163\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<div>4<\/div>\n<div>5<\/div>\n<div>6<\/div>\n<\/td>\n<td>\n<div>\n<div><code>pm = dynamic<\/code><\/div>\n<div><code>pm.max_children = 10<\/code><\/div>\n<div><code>pm.start_servers = 1<\/code><\/div>\n<div><code>pm.min_spare_servers = 1<\/code><\/div>\n<div><code>pm.max_spare_servers = 4<\/code><\/div>\n<div><code>pm.max_requests = 500<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>This will bring down the number of children processes and free up some RAM.<\/p>\n<h2>Step 5 : Restart PHP-FPM<\/h2>\n<div>\n<div id=\"highlighter_175794\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<\/td>\n<td>\n<div>\n<div><code>service php5-fpm restart<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>This command will restart PHP-FPM.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites. Source :\u00a0PHP-FPM Website PHP-FPM is far better than the standard mod_php implementation of PHP and also easier to implement that spawn-fcgi. PHP-FPM works like an application that loads and kills PHP instances [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[60],"tags":[155,156],"class_list":["post-392","post","type-post","status-publish","format-standard","hentry","category-linux","tag-configure-optimise-php5-with-php5-fpm","tag-install"],"acf":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts\/392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/comments?post=392"}],"version-history":[{"count":0,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts\/392\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/media?parent=392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/categories?post=392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/tags?post=392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}