I’ve readed a lot of tutorials of using nginx and php-fpm.
I’m still using apache2 much more due the .htaccess easiness that allow with rewriting and password protect (despite using other modules like mod_svn, etc)
Even I haven’t found a 100% transparent solution like ngninx, here is what I’m using to work with php-fpm and apache2. Here are the steps in debian:
echo "deb http://packages.dotdeb.org stable all" >> /etc/apt/sources.listapt-get updateapt-get install libapache2-mod-fastcgi apache2-mpm-worker php5-fpm php5-common php5-cli- do all the
apt-getof allphp5-* modulesyou want - Add the following to a new file:
/etc/apache2/mods-enabled/fpm.loadAddType application/x-httpd-fastphp5 .php .phtml Action application/x-httpd-fastphp5 /fast-cgi-fake-handler
- in
/etc/php5/fpm/pool.d/www.confchange:listen = 127.0.0.1:9000
for:
; listen = 127.0.0.1:9000 listen = /var/run/php-fpm.socket
This will enable the unix socket which should be faster
/etc/init.d/php-fpm restart/etc/init.d/apache2 restart
With this you will be able to use php-fpm through a /fast-cgi-fake-handler so for example in your /etc/apache2/sites-enabled/000-default your file will look like:
FastCGIExternalServer /var/www/fast-cgi-fake-handler -socket /var/run/php-fpm.socket DocumentRoot /var/www
The system will rewrite /index.php path into: /fast-cgi-fake-handler/index.php which will be passed to the fastcgi
This have two problems:
- You need to set the
FastCGIExternalServerlike${DOCUMENT_ROOT}/fast-cgi-fake-handlerin all your virtual hosts to make it work - Zend framework and other which use the consume all url’s pattern to pass through
index.phpwill not work as will generate an endless loop, there is an easy solution, in your.htaccessuse afterRewriteEngine On:RewriteRule ^fast-cgi-fake-handler/ - [L,NC]
this will skip processing all urls which contain “
fast-cgi-fake-handler” at start; or of course use aRewriteCondto avoid this.