SDB:Apache FastCGI and PHP-FPM configuration

Jump to: navigation, search

Why PHP-FPM

php-fpm is harder to configure than apache2-mod_php, but it provides some advantages:

  1. Support event mode (mod_php only supports prefork mode)
  2. Support HTTP2
  3. Better performance

How to

Disable apache2-mod_php8:

sudo a2dismod php8

Install and enable apache2-mod_fcgid and php8-fpm:

sudo zypper install apache2-mod_fcgid php8-fpm php8-pear
sudo zypper install apache2-event (optional but recommended; prefork is only good for mod_php)
sudo a2enmod proxy
sudo a2enmod proxy_fcgi
sudo a2enmod setenvif 
sudo a2enmod fcgid

For feature parity with mod_php add PEAR to the environment:

In /etc/php8/fpm/php-fpm.d/www.conf add at the end:

php_admin_value[include_path] = /usr/share/php/PEAR

Start and enable PHP-FPM deamon:

sudo systemctl start php-fpm
sudo systemctl enable php-fpm

Edit Apache FastCGI configuration:

sudo vi /etc/apache2/conf.d/mod_fcgid.conf

At the end of file, change:

#<FilesMatch "\.php$">
#    AddHandler fcgid-script .php
#    Options +ExecCGI
#    FcgidWrapper /srv/www/cgi-bin/php7 .php
#</FilesMatch>

to:

DirectoryIndex index.php
<FilesMatch "\.php$">
    SetHandler "proxy:fcgi://127.0.0.1:9000/"
    #CGIPassAuth on
</FilesMatch>

For something like Sabre, iRony oder APCu you should enable CGIPassAuth.


Set Apache MPM to event (optional but recommended):

In /etc/sysconfig/apache2 make sure to set

 APACHE_MPM="event"

Finally restart Apache via

sudo systemctl restart apache2