Running PHP as FastCGI with Apache 2.x on Ubuntu 12.x and later

The instructions given below are to be run from the terminal. This is the only list of instructions which actually worked. I have reproduced the steps as a simple list to be followed based on the post made by JDawgg.

Install Apache Mpm worker and PHP5 FPM modules:

sudo apt-get install apache2-mpm-worker
sudo apt-get install libapache2-mod-fastcgi php5-fpm

 

Enable/Disable mods in Apache

sudo a2dismod php5 mpm_prefork
sudo a2enmod actions fastcgi alias mpm_worker

 

Create php5.fcgi and provide the correct user rights.

sudo touch /usr/lib/cgi-bin/php5.fcgi
sudo chown -R www-data:www-data /usr/lib/cgi-bin

 

Add a configuration for php5.fpm in Apache2

sudo vi /etc/apache2/conf-available/php5-fpm.conf

with the contents:

<IfModule mod_fastcgi.c>
AddHandler php5.fcgi .php
Action php5.fcgi /php5.fcgi
Alias /php5.fcgi /usr/lib/cgi-bin/php5.fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5.fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization -idle-timeout 3600
<Directory /usr/lib/cgi-bin>
Require all granted
</Directory>
</IfModule>

 

Enable php5-fpm module in Apache2

sudo a2enconf php5-fpm

Restart Apache2 and PHP-FPM

sudo service apache2 restart
sudo service php5-fpm restart

If you do a phpinfo() on a test page, then the Server API information should show FPM/FastCGI instead of the usual Apache 2.0 Handler.

 

phpinfo() 2015-11-17 15-10-17

 

 

 

 

 

 

 

 

 

 

 

 

 

Be the first to comment

Leave a Reply

Your email address will not be published.


*