Apache with php-fpm: Difference between revisions

From Alpine Linux
No edit summary
Line 24: Line 24:
{{Cmd|cp /etc/apache2/original/extra/httpd-mpm.conf /etc/apache2/conf.d/}}
{{Cmd|cp /etc/apache2/original/extra/httpd-mpm.conf /etc/apache2/conf.d/}}


put these lines in yout httpd.conf or vhost files, don't forget to change the path
put these lines in your httpd.conf or vhost files, don't forget to change the path
  ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/localhost/htdocs/$1                                           
  ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/localhost/htdocs/$1                                           
  DirectoryIndex /index.php
  DirectoryIndex /index.php
Line 34: Line 34:
'''(re)start apache2 and php-fpm'''
'''(re)start apache2 and php-fpm'''
{{Cmd|/etc/init.d/apache2 restart && /etc/init.d/php-fpm restart }}
{{Cmd|/etc/init.d/apache2 restart && /etc/init.d/php-fpm restart }}
===More info===
===More info===
[https://wiki.apache.org/httpd/PHP-FPM apache wiki]
[https://wiki.apache.org/httpd/PHP-FPM apache wiki]
[http://php.net/manual/en/install.fpm.configuration.php php-fpm manual]
[http://php.net/manual/en/install.fpm.configuration.php php-fpm manual]
[[Category:Server]]
[[Category:Server]]

Revision as of 08:24, 17 September 2014

Apache and php

There are 4 different ways to use php with apache

  • cgi
  • fcgi
  • mod_php
  • php-fpm

Here is a comparison why fpm is the better way. In short it works with apache event mpm, has better security, can have per vhost pool configuration, better process management, .... When used with apache event mpm, it's the most memory efficient setup that you can achieve with apache + php. Whether it's better than nginx + php-fpm depends on your setup, contents and preference.

Step by step (apache2 event mpm + php+fpm)

install apache2 and php-fpm

apk add apache2-proxy php-fpm

configure apache2

in /etc/apache2/httpd.conf

Comment line:

LoadModule mpm_prefork_module modules/mod_mpm_prefork.so and

Uncomment line:

#LoadModule mpm_event_module modules/mod_mpm_event.so

copy the mpm config, and adapt it to suit you needs.

cp /etc/apache2/original/extra/httpd-mpm.conf /etc/apache2/conf.d/

put these lines in your httpd.conf or vhost files, don't forget to change the path

ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/localhost/htdocs/$1                                          
DirectoryIndex /index.php

tune php-fpm

edit the file /etc/php/php-fpm.conf to suit you needs

(re)start apache2 and php-fpm

/etc/init.d/apache2 restart && /etc/init.d/php-fpm restart

More info

apache wiki php-fpm manual