I have managed to get FastCGI working with Apache 2.4 on Ubuntu 16.04 by adapting instructions from this askubuntu thread, this HowtoForge document, and this Digital Ocean tutorial.
All those sources say to create
/etc/apache2/conf-available/php7.0-fpm.conf and tell you what to put in it. But after installing
php-fpm, I already have that file, with the following contents:
# Redirect to local php-fpm if mod_php is not available <IfModule !mod_php7.c> # Enable http authorization headers SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1 <FilesMatch ".+\.ph(p?|t|tml)$"> SetHandler "proxy:unix:/run/php/php7.0-fpm.sock|fcgi://localhost" </FilesMatch> <FilesMatch ".+\.phps$"> # Deny access to raw php sources by default # To re-enable it's recommended to enable access to the files # only in specific virtual host or directory Require all denied </FilesMatch> # Deny access to files without filename (e.g. '.php') <FilesMatch "^\.ph(p?|t|tml|ps)$"> Require all denied </FilesMatch> </IfModule>
So I have instead created my own conf and put the code from the instructions in it and enabled it.
What is the existing
php7.0-fpm.conf for? If I enable it in addition to my conf, my websites stop working. I'm worried that I'm no doing this the way it's intended to be done and could have problems in the future. It's really difficult to find good, current documentation on this.
For reference, here is my entire procedure:
sudo apt install libapache2-mod-fastcgi php-fpm sudo a2dismod php7.0 mpm_prefork sudo a2enmod actions fastcgi alias mpm_worker sudoedit /etc/apache2/conf-available/custom-fpm.conf
<IfModule mod_fastcgi.c> AddHandler php7-fcgi .php Action php7-fcgi /php7-fcgi virtual Alias /php7-fcgi /usr/lib/cgi-bin/php7-fcgi FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi -socket /var/run/php/php7.0-fpm.sock -pass-header <Directory /usr/lib/cgi-bin> Require all granted </Directory> </IfModule>
sudo a2enconf custom-fpm sudo systemctl restart apache2 && sudo systemctl restart php7.0-fpm
Thanks in advance for your help.