{"id":220,"date":"2014-11-19T23:13:13","date_gmt":"2014-11-20T04:13:13","guid":{"rendered":"http:\/\/devroar.com\/?p=220"},"modified":"2014-11-20T11:57:58","modified_gmt":"2014-11-20T16:57:58","slug":"configuring-php5-fpm-pools-with-suhosin-custom-php-ini-settings","status":"publish","type":"post","link":"http:\/\/devroar.com\/index.php\/2014\/11\/19\/configuring-php5-fpm-pools-with-suhosin-custom-php-ini-settings\/","title":{"rendered":"Configuring PHP5-FPM Pools with Suhosin \/ Custom php.ini Settings"},"content":{"rendered":"<p><a href=\"http:\/\/suhosin.org\/stories\/index.html\"><img src=\"http:\/\/devroar.com\/wp-content\/uploads\/2014\/11\/suhosin.jpg\" alt=\"Suhosin\" class=\"alignright\" \/><\/a><\/p>\n<p>If you have followed my server setup guide you should already have php5-fpm installed using some pretty basic settings. Pools are very powerful and you can do a lot more with them if you choose. You can configure new pools that are only used by specific domain names, you might want this if you have a website that gets a lot more traffic than others on your server. Dedicated pools could make the website more stable and guarantee resources. You can also configure specific php.ini settings on a specific pool if you need to for instance lock down a specific domain so it can&#8217;t use certain functions, increase \/ decrease memory allowance, etc. It can be very useful. <\/p>\n<p><a href=\"http:\/\/suhosin.org\/stories\/index.html\">Suhosin<\/a> is an extension for the web server that allows you to further lock down various aspects of your PHP install. You can disable eval() which you can not do with the php.ini as it&#8217;s not a &#8220;real&#8221; function it&#8217;s a language construct. Basically Suhosin gives you a lot more power and flexibility, that normally you would not be able to attain. Suhosin works very well with php5-fpm pools, you can set it&#8217;s configuration variables just the same as you would with php.ini settings.<\/p>\n<p><!--more--><\/p>\n<h3 style=\"clear: left;\">Configure \/ Restructure FPM Pools<\/h3>\n<p>To begin, I like to trim my www.conf down to the minimum. Make a backup of the original somewhere in case you want to look at some of the commented out settings.<\/p>\n<p>Replace the contents of <em>\/etc\/php5\/fpm\/pool.d\/www.conf<\/em> with<br \/>\n<code><br \/>\n[www]<\/p>\n<p>user = www-data<br \/>\ngroup = www-data<\/p>\n<p>listen.owner = www-data<br \/>\nlisten.group = www-data<\/p>\n<p>pm = dynamic<\/p>\n<p>chdir = \/<\/p>\n<p>pm.max_children = 10<br \/>\npm.start_servers = 2<br \/>\npm.min_spare_servers = 1<br \/>\npm.max_spare_servers = 3<\/p>\n<p>listen = \/var\/run\/php5-fpm.sock<br \/>\n<\/code><\/p>\n<p>Now create a new file at <em>\/etc\/php5\/fpm\/pool.d\/www2.conf<\/em> and paste in the following<\/p>\n<p><code><br \/>\n[www2]<\/p>\n<p>user = www-data<br \/>\ngroup = www-data<\/p>\n<p>listen.owner = www-data<br \/>\nlisten.group = www-data<\/p>\n<p>pm = dynamic<\/p>\n<p>chdir = \/<\/p>\n<p>;commented out for after we install suhosin<br \/>\n;php_flag[suhosin.executor.disable_eval] = On<\/p>\n<p>pm.max_children = 5<br \/>\npm.start_servers = 1<br \/>\npm.min_spare_servers = 1<br \/>\npm.max_spare_servers = 3<\/p>\n<p>listen = \/var\/run\/php5-fpm-www2.sock<br \/>\n<\/code><\/p>\n<p>You&#8217;ve now made a second pool with tweaked settings. Next up is installing suhosin.<\/p>\n<h3>Installing suhosin<\/h3>\n<p>Go download the latest version of suhosin from their <a href=\"http:\/\/suhosin.org\/stories\/download.html\">download<\/a> page.<\/p>\n<p><code><br \/>\ncd ~\/installs<br \/>\nwget http:\/\/download.suhosin.org\/suhosin-0.9.36.tgz<br \/>\ntar -xvf suhosin-0.9.36.tgz<br \/>\ncd suhosin-0.9.36<br \/>\nphpize<br \/>\n.\/configure<br \/>\nmake<br \/>\nmake install<br \/>\n<\/code><\/p>\n<p>Now we need to enable the extension. Create a new file at <em>\/etc\/php5\/mods-available\/suhosin.ini<\/em> put this in the file<br \/>\n<code><br \/>\nextension=suhosin.so<br \/>\n<\/code><\/p>\n<p>Now we need to create a symlink pointing to it.<br \/>\n<code><br \/>\nsudo ln -s \/etc\/php5\/mods-available\/suhosin.ini \/etc\/php5\/fpm\/conf.d\/suhosin.ini<br \/>\n<\/code><\/p>\n<p>Now edit your www2.conf and uncomment the line that is commented out to disable eval on that pool&#8217;s php config. You can actually put any settings that would normally go in php.ini into this pool file to change specific php settings only on certain domains. <em>Example: php_flag[disabled_functions] = &#8220;phpinfo&#8221; would disable the phpinfo() function.<\/em><\/p>\n<p>Then, open up the domain&#8217;s vhost file. <em>\/etc\/nginx\/sites-available\/[domain].conf<\/em> and change the socket line to match the new pool you created.<br \/>\n<code><br \/>\nfastcgi_pass unix:\/var\/run\/php5-fpm-www2.sock;<br \/>\n<\/code><\/p>\n<p>Reboot your nginx and restart php5-fpm<br \/>\n<code><br \/>\nsudo service nginx restart<br \/>\nsudo service php5-fpm restart<br \/>\n<\/code><\/p>\n<p>Suhosin should be enabled now, try looking at a phpinfo file to verify. You should see a Suhosin section that lists &#8220;suhosin.executor.disable_eval&#8221; as being turned on.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Download article as PDF If you have followed my server setup guide you should already have php5-fpm installed using some pretty basic settings. Pools are very powerful and you can do a lot more with them if you choose. You<span class=\"ellipsis\">&hellip;<\/span><\/p>\n<div class=\"read-more\"><a href=\"http:\/\/devroar.com\/index.php\/2014\/11\/19\/configuring-php5-fpm-pools-with-suhosin-custom-php-ini-settings\/\">Read more &#8250;<\/a><\/div>\n<p><!-- end of .read-more --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2,53],"tags":[130,36,127,129,44,128,131,132,126],"_links":{"self":[{"href":"http:\/\/devroar.com\/index.php\/wp-json\/wp\/v2\/posts\/220"}],"collection":[{"href":"http:\/\/devroar.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/devroar.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/devroar.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/devroar.com\/index.php\/wp-json\/wp\/v2\/comments?post=220"}],"version-history":[{"count":17,"href":"http:\/\/devroar.com\/index.php\/wp-json\/wp\/v2\/posts\/220\/revisions"}],"predecessor-version":[{"id":248,"href":"http:\/\/devroar.com\/index.php\/wp-json\/wp\/v2\/posts\/220\/revisions\/248"}],"wp:attachment":[{"href":"http:\/\/devroar.com\/index.php\/wp-json\/wp\/v2\/media?parent=220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/devroar.com\/index.php\/wp-json\/wp\/v2\/categories?post=220"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/devroar.com\/index.php\/wp-json\/wp\/v2\/tags?post=220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}