PHP 7.2 fastcgi doesn't work on Ubuntu 18.04 server
Solution 1
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 2
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 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.
Related videos on Youtube
Duddy67
Updated on September 18, 2022Comments
-
Duddy67 almost 2 years
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.
-
Duddy67 about 6 yearsSo what about the
libapache2-mod-fcgid
package ? That's the one I've installed. It isn't supposed to replace thelibapache2-mod-fastcgi
package ? -
Duddy67 about 6 yearsOk 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
thensudo 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 about 6 yearsIn 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 about 6 yearsI 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. -
scones about 5 yearsi advise against using this module manually. it crashes regularly on my machines.
-
Tommy Ngo about 5 yearsI don't advise to use
libapache2-mod-fastcgi
module in Bionic or newer distro. Apache2 providesmod_proxy_fcgi
module that proxies fcgi requests. -
SubjectX over 4 yearsNot 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..
-
erotavlas about 4 yearsI have ubuntu server 18.04 and zentyal 6.1. On the first, your suggestion and the various guides server-world.info/en/note?os=Ubuntu_18.04&p=httpd&f=13 do not work while they do not work on the second. Any idea?