PHP 7.2 fastcgi doesn't work on Ubuntu 18.04 server

I've just installed LAMP on a Ubuntu 18.04 server and I can't get PHP fastcgi to work. Here's my settings:

My fpm PHP file: /etc/php/7.2/fpm/pool.d/sites.mydomain.conf

[sites.mydomain]
 ...
user = sites
group = sites
 ...
listen = /run/php/php7.2-fpm.sites.mydomain.sock
 ...
listen.owner = www-data
listen.group = www-data

then

sudo service php7.2-fpm reload
sudo service php7.2-fpm restart

My virtual host file: etc/apache2/sites-available/sites.mydomain.conf

    ServerName sites.mydomain
    ServerAdmin webmaster@localhost
    DocumentRoot /srv/www/sites/html

    <IfModule mod_fastcgi.c>
      AddHandler php7-fcgi-sites .php
      Action php7-fcgi-sites /php7-fcgi-sites
      Alias /php7-fcgi-sites /usr/lib/cgi-bin/php7-fcgi-sites
     FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi-sites -idle-timeout 60 -socket /var/run/php/php7.2-fpm.sites.mydomain.sock -pass-header Authorization

      <Directory /usr/lib/cgi-bin>
        Require all granted
      </Directory>
    </IfModule>

    <Directory /srv/www/sites/html>
      Options Indexes FollowSymLinks MultiViews
      AllowOverride None
      Require all granted
    </Directory>

then

sudo a2enmod actions
sudo service apache2 restart

But PHP is not interpreted when running scripts, pages are displayed as plain text.
Can someone tells me what's wrong in my setting ?

Note: I set it exactly the same way on my Ubuntu 16.04 server and it works fine.


Solution 1:

I unfortunately took the advice of the answers here, which either incorrect, or a tangental.

After a little digging, i realised that the module in question (proxy_fcgi) is actually part of the bionic apache2-bin package

so all that was needed was:

a2enmod proxy_fcgi

Solution 2:

Finally there is no need to install the libapache2-mod-fastcgi package.
The trick takes place in the etc/apache2/sites-available/sites.mydomain.conf file (see my example above).
Replace the <IfModule mod_fastcgi.c> part with

<FilesMatch "\.php$">
   SetHandler "proxy:unix:///var/run/php/php7.2-fpm.sites.mydomain.sock|fcgi://sites/"
</FilesMatch>

and you're done.
Hope it helps.

Solution 3:

So... I did some digging on this.

First, it seems that mod_fcgid is the free version of mod_fastcgi, but sends fewer requests per stream, so is slower.

But both seem to be fairly outdated, and it seems the libapache2-mod-fastcgi package was pulled from Debian for various reasons: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=835374

However, as of apache 2.4.10, it is best to use the mod_proxy_fcgi module with php fpm. https://serverfault.com/questions/783173/differences-between-mod-fastcgi-and-mod-proxy-fcgi

Hope this helps clear things up. Most php-fpm guides around don't seem to be updated for mod_proxy_fcgi use yet, so might be causing confusion.