6

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.

8

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
  • 1
    In order to get it work with proxy_fcgi I also had to enable the php conf: sudo a2enconf php7.2-fpm but unfortunately my php configuration file /etc/php/7.2/fpm/pool.d/sites.mydomain.conf (see above for more detail) is not taken into account. The process user is www-data instead of my username (ie: sites). – Duddy67 May 19 '18 at 8:10
  • 1
    I finally got it to work by replacing the <IfModule> part with: <FilesMatch "\.php$"> SetHandler "proxy:unix:///var/run/php/php7.2-fpm.sites.mydomain.sock|fcgi://sites/" </FilesMatch> in the apache vhost conf. – Duddy67 May 20 '18 at 12:16
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.

3

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.

  • Not sure if I'm doing something wrong, but using this solution does nothing for me. It doesnt return error, thats something, but apache doesnt change its behaviour. Whats more, I can enter bogus data into this line and my Moodle instalation would still work.. – SubjectX Jan 14 at 9:06
0

From what I gather, it could be that libapache2-mod-fastcgi package is not available for bionic yet. As such, there is no fastcgi module available for Apache2.

  • So what about the libapache2-mod-fcgid package ? That's the one I've installed. It isn't supposed to replace the libapache2-mod-fastcgi package ? – Duddy67 Apr 30 '18 at 6:16
  • Ok I got it. I've downloaded the fastcgi package here: wget http://mirrors.kernel.org/ubuntu/pool/multiverse/liba/libapache-mod-fastcgi/libapache2-mod-fastcgi_2.4.7~0910052141-1.2_amd64.deb then sudo dpkg -i <package name> sudo a2enmod fastcgi sudo service apache2 restart and now everything works fine. But still, I'm dubious about 2 points: 1) Is it safe to do it that way regarding Ubuntu updates and package dependencies ? 2) FastCgi is widely used with Apache servers. Why Ubuntu removed it from its repositories without any other alternatives left ? – Duddy67 Apr 30 '18 at 6:59
  • i advise against using this module manually. it crashes regularly on my machines. – scones May 3 '19 at 14:17
  • 1
    I don't advise to use libapache2-mod-fastcgi module in Bionic or newer distro. Apache2 provides mod_proxy_fcgi module that proxies fcgi requests. – Tommy Ngo May 6 '19 at 5:03
0

I upgraded from 17.10 to 18.04 and pages were just loading with the contents of the php file rather than rendering the page. All I had to do was update my /etc/apache2/mods-enabled/fastcgi.conf file with the following:

<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.sock -pass-header Authorization

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.