Apache with php-fpm: Difference between revisions

From Alpine Linux
No edit summary
m (Added category: PHP)
(5 intermediate revisions by 2 users not shown)
Line 9: Line 9:


===Step by step (apache2 event mpm + php+fpm) ===
===Step by step (apache2 event mpm + php+fpm) ===
'''install apache2 and php-fpm'''
'''install apache2 and php5-fpm'''
{{Cmd|apk add apache2-proxy php-fpm}}
{{Cmd|apk add apache2-proxy php5-fpm}}


'''configure apache2'''
'''configure apache2'''
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
  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


'''tune php-fpm'''
'''tune php-fpm'''
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]]
[[Category:PHP]]

Revision as of 03:35, 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