Apache with php-fpm: Difference between revisions

From Alpine Linux
(Created page with "=Apache and php= * cgi * fcgi * mod_php * php-fpm =Step by step=")
 
m (Added category: PHP)
(16 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=Apache and php=
===Apache and php===
There are 4 different ways to use php with apache
* cgi
* cgi
* fcgi
* fcgi
* mod_php
* mod_php
* php-fpm
* php-fpm
Here is a comparison why [http://php-fpm.org/about 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=
===Step by step (apache2 event mpm + php+fpm) ===
'''install apache2 and php5-fpm'''
{{Cmd|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.
{{Cmd|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'''
{{Cmd|/etc/init.d/apache2 restart && /etc/init.d/php-fpm restart }}
 
===More info===
[https://wiki.apache.org/httpd/PHP-FPM apache wiki]
[http://php.net/manual/en/install.fpm.configuration.php php-fpm manual]
[[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