Apache with php-fpm: Difference between revisions

From Alpine Linux
m (Edited from Server to new subcategory: Web Server)
Line 43: Line 43:
[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:Web Server]]

Revision as of 03:34, 21 September 2017

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 php5-fpm

apk add apache2-proxy php5-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

This step is not needed any more

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

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

put the following in /etc/apache2/conf.d/slotmem_shm.conf

LoadModule slotmem_shm_module modules/mod_slotmem_shm.so

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