{"id":481,"date":"2012-11-02T14:05:14","date_gmt":"2012-11-02T13:05:14","guid":{"rendered":"http:\/\/elkano.org\/blog\/?page_id=481"},"modified":"2016-12-14T16:19:52","modified_gmt":"2016-12-14T15:19:52","slug":"apache2-mpm-worker-fastcgi-php5-fpm-on-debian","status":"publish","type":"post","link":"https:\/\/elkano.org\/blog\/apache2-mpm-worker-fastcgi-php5-fpm-on-debian\/","title":{"rendered":"Apache2 mpm worker + fastcgi + php5-fpm on debian"},"content":{"rendered":"<p>Install required packages:<\/p>\n<pre class=\"dontquote prettyprint lang-xml\"># apt-get install libapache2-mod-fastcgi apache2-mpm-worker php5-fpm<\/pre>\n<p>To install php5-fpm on debian squeeze you can add <a href=\"http:\/\/www.dotdeb.org\" target=\"_blank\">dotdeb<\/a> repository to your sources.list<\/p>\n<pre class=\"dontquote prettyprint lang-xml\">\r\ndeb http:\/\/packages.dotdeb.org stable all\r\ndeb-src http:\/\/packages.dotdeb.org stable all\r\n<\/pre>\n<p>Then run:<\/p>\n<pre class=\"dontquote prettyprint lang-xml\">\r\n# wget -O- &quot;http:\/\/www.dotdeb.org\/dotdeb.gpg&quot; | apt-key add -\r\n# apt-get update\r\n<\/pre>\n<p>Configure php5-fpm pool in \/etc\/php5\/fpm\/pool.d\/, www.conf by default, but you can change the name and set a new one based on virtual host.<\/p>\n<pre class=\"dontquote prettyprint lang-xml\">\r\nuser = user\r\ngroup = group\r\nlisten = \/var\/run\/php5-fpm.sock\r\nlisten.owner = user\r\nlisten.group = group\r\npm = dynamic\r\npm.max_children = 150\r\npm.start_servers = 30\r\npm.min_spare_servers = 15\r\npm.max_spare_servers = 40\r\npm.max_requests = 1000<\/pre>\n<p>You can also set a sock file name identifying the pool name. I am using only one pool in the server, so I leave it as default.<br \/>\nConfigure Apc in \/etc\/php5\/fpm\/conf.d\/20-apc<\/p>\n<pre class=\"dontquote prettyprint lang-xml\">extension=apc.so\r\napc.enabled=1\r\napc.stat=0\r\napc.mmap_file_mask = \/tmp\/apc-XXXXXX\r\napc.enable_cli = 0\r\napc.max_file_size = 2M\r\napc.stat_ctime = 0\r\napc.shm_size = 128M\r\napc.canonicalize=0<\/pre>\n<p>Restart php5-fpm with the new configuration:<\/p>\n<pre class=\"dontquote prettyprint lang-xml\">\/etc\/init.d\/php5-fpm restart<\/pre>\n<p>Now, configure apache to be able to pass php requests to php5-fpm server:<\/p>\n<p>Enable actions module if it isn&#8217;t enabled yet<\/p>\n<pre class=\"dontquote prettyprint lang-xml\"># a2enmod actions<\/pre>\n<p>Configure fastcgi, edit file \/etc\/apache2\/mods-enabled\/fastcgi.conf<\/p>\n<pre class=\"dontquote prettyprint lang-xml\">&lt;IfModule mod_fastcgi.c&gt;\r\n  AddHandler fastcgi-script .fcgi\r\n  #FastCgiWrapper \/usr\/lib\/apache2\/suexec\r\n  FastCgiIpcDir \/var\/lib\/apache2\/fastcgi\r\n\r\n  Alias \/php5.fcgi \/var\/lib\/apache2\/fastcgi\/php5.fcgi\r\n  FastCGIExternalServer \/var\/lib\/apache2\/fastcgi\/php5.fcgi -flush -socket \/var\/run\/php5-fpm.sock\r\n  # application\/x-httpd-php                        phtml pht php\r\n  # application\/x-httpd-php3                       php3\r\n  # application\/x-httpd-php4                       php4\r\n  # application\/x-httpd-php5                       php\r\n  &lt;FilesMatch &quot;.+\\.ph(p[345]?|t|tml)$&quot;&gt;\r\n    SetHandler application\/x-httpd-php\r\n  &lt;\/FilesMatch&gt;\r\n  Action application\/x-httpd-php \/php5.fcgi\r\n  &lt;Directory &quot;\/var\/lib\/apache2\/fastcgi&quot;&gt;\r\n    Order deny,allow\r\n    Deny from all\r\n    &lt;Files &quot;php5.fcgi&quot;&gt;\r\n      Order allow,deny\r\n      Allow from all\r\n    &lt;\/Files&gt;\r\n  &lt;\/Directory&gt;\r\n\r\n&lt;\/IfModule&gt;<\/pre>\n<p>If you have several virtualhosts, each one with diferents pools, you can especifly the FastCGIExternalServer directive in each virtualhost configuration.<\/p>\n<p>Create file \/var\/lib\/apache2\/fastcgi\/php5.fcgi<\/p>\n<pre class=\"dontquote prettyprint lang-xml\"># touch \/var\/lib\/apache2\/fastcgi\/php5.fcgi<\/pre>\n<p>Restart apache:<\/p>\n<pre class=\"dontquote prettyprint lang-xml\"># apachectl restart<\/pre>\n<p>And now test if your php files are served correctly by apache.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Install required packages: # apt-get install libapache2-mod-fastcgi apache2-mpm-worker php5-fpm To install php5-fpm on debian squeeze you can add dotdeb repository to your sources.list deb http:\/\/packages.dotdeb.org stable all deb-src http:\/\/packages.dotdeb.org stable all Then run: # wget -O- &quot;http:\/\/www.dotdeb.org\/dotdeb.gpg&quot; | apt-key add &#8211; # apt-get update Configure php5-fpm pool in \/etc\/php5\/fpm\/pool.d\/, www.conf by default, but you can [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[75,205,204],"_links":{"self":[{"href":"https:\/\/elkano.org\/blog\/wp-json\/wp\/v2\/posts\/481"}],"collection":[{"href":"https:\/\/elkano.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elkano.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elkano.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elkano.org\/blog\/wp-json\/wp\/v2\/comments?post=481"}],"version-history":[{"count":20,"href":"https:\/\/elkano.org\/blog\/wp-json\/wp\/v2\/posts\/481\/revisions"}],"predecessor-version":[{"id":506,"href":"https:\/\/elkano.org\/blog\/wp-json\/wp\/v2\/posts\/481\/revisions\/506"}],"wp:attachment":[{"href":"https:\/\/elkano.org\/blog\/wp-json\/wp\/v2\/media?parent=481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elkano.org\/blog\/wp-json\/wp\/v2\/categories?post=481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elkano.org\/blog\/wp-json\/wp\/v2\/tags?post=481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}