php7-fpm
Contents
- This Howto is about configuring php7-fpm with apache2 fastcgi.
It may also possible to configure it using mod_proxy and mod_proxy_fcgi which also hast fastcgi support. Please have a look at https://httpd.apache.org/docs/current/mod/mod_proxy_fcgi.html if you are interested in an alternative way of configuration.
Installation
1 aptitude install apache2 libapache2-mod-fastcgi php7.0 php7-fpm
Configure php7-fpm
/etc/php/7.0/fpm/pool.d/www.conf
Disable the SetHandler directive it inhibits using mod_fastcgi.
1 root@puls:/etc/php/7.0/fpm/pool.d# cat /etc/apache2/conf-available/php7.0-fpm.conf
2 # Redirect to local php-fpm if mod_php is not available
3 <IfModule !mod_php7.c>
4 # Enable http authorization headers
5 SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
6
7 #<FilesMatch ".+\.ph(p[3457]?|t|tml)$">
8 # SetHandler "proxy:unix:/run/php/php7.0-fpm.sock|fcgi://localhost:9000"
9 #</FilesMatch>
10 <FilesMatch ".+\.phps$">
11 # Deny access to raw php sources by default
12 # To re-enable it's recommended to enable access to the files
13 # only in specific virtual host or directory
14 Require all denied
15 </FilesMatch>
16 # Deny access to files without filename (e.g. '.php')
17 <FilesMatch "^\.ph(p[3457]?|t|tml|ps)$">
18 Require all denied
19 </FilesMatch>
20 </IfModule>
Configure fastcgi
/usr/lib/cgi-bin must later be allowed.
The file php7-fcgi is only a dummy and must not exist.
- Configure the IP and Port to connect.
1 root@puls:/etc/php/7.0/fpm/pool.d# cat /etc/apache2/mods-available/fastcgi.conf
2 <IfModule mod_fastcgi.c>
3 AddHandler fastcgi-script .fcgi
4 #FastCgiWrapper /usr/lib/apache2/suexec
5 FastCgiIpcDir /var/lib/apache2/fastcgi
6
7 AddHandler php7-fcgi .php
8 Action php7-fcgi /php7-fcgi
9 Alias /php7-fcgi /usr/lib/cgi-bin/php7-fcgi
10 #FastCgiExternalServer php5-fpm_www-mail -host 127.0.0.1:9000 -pass-header Authorization
11 FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi -host 127.0.0.1:9000 -pass-header Authorization
12 #FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi -socket /var/run/php5-fpm_www-mail.sock -pass-header Authorization
13 #FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi -socket /var/lib/apache2/fastcgi/php5-fpm_www-mail.sock -pass-header Authorization
14 </IfModule>
Enable Subsystems
Enable necessary modules
- The with apache2.4 introduced define-directives are the reason, why mod_cgid should be enabled.
1 root@puls:/etc/php/7.0/fpm/pool.d# cat /etc/apache2/conf-available/serve-cgi-bin.conf
2 <IfModule mod_alias.c>
3 <IfModule mod_cgi.c>
4 Define ENABLE_USR_LIB_CGI_BIN
5 </IfModule>
6
7 <IfModule mod_cgid.c>
8 Define ENABLE_USR_LIB_CGI_BIN
9 </IfModule>
10
11 <IfDefine ENABLE_USR_LIB_CGI_BIN>
12 ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
13 <Directory "/usr/lib/cgi-bin">
14 AllowOverride None
15 Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
16 Require all granted
17 </Directory>
18 </IfDefine>
19 </IfModule>
20
21 # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
22
Enable necessary configuration
- You no longer need mpm_prefork, enable mpm_event
1 root@puls:/etc/php/7.0/fpm/pool.d# a2dismod mpm_prefork
2 Module mpm_prefork disabled.
3 To activate the new configuration, you need to run:
4 service apache2 restart
5 root@puls:/etc/php/7.0/fpm/pool.d# a2enmod mpm_event
6 Considering conflict mpm_worker for mpm_event:
7 Considering conflict mpm_prefork for mpm_event:
8 Enabling module mpm_event.
9 To activate the new configuration, you need to run:
10 service apache2 restart
11 root@puls:/etc/php/7.0/fpm/pool.d# service apache2 restart
- Done