Apache with php-fpm: Difference between revisions

From Alpine Linux
No edit summary
No edit summary
Line 21: Line 21:
  #LoadModule mpm_event_module modules/mod_mpm_event.so
  #LoadModule mpm_event_module modules/mod_mpm_event.so


This step is not needed any more
''This step is not needed any more''
 
copy the mpm config, and adapt it to suit you needs.
copy the mpm config, and adapt it to suit you needs.
{{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/}}
Line 27: Line 28:
put the following in /etc/apache2/conf.d/slotmem_shm.conf
put the following in /etc/apache2/conf.d/slotmem_shm.conf
  LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
  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
put these lines in your httpd.conf or vhost files, don't forget to change the path

Revision as of 12:36, 4 July 2016

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

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