This guide explains how to configure Apache under Debian in order to run PHP under the fastcgi
module instead of mod_php
. By default Apache loads mod_php
for all file types and consumes more resources but with fastcgi
we can configure Apache to pass just PHP files to the PHP interpreter.
The libapache2-mod-fastcgi
module is needed that can be installed by editing /etc/apt/sources.list
and then adding contrib
and non-free
to the default repository. For example:
deb http://uk.debian.org/debian/ jessie main contrib non-free deb-src http://uk.debian.org/debian/ jessie main contrib non-free
First, disable the standard php5 module with:
a2dismod php5
After that, run aptitude update
and then install the necessary packages:
aptitude install php5-fpm libapache2-mod-fastcgi apache2
Next, we create or overwrite the file at /etc/apache2/mods-available/fastcgi.conf
with the following contents:
<IfModule mod_fastcgi.c> AddType application/x-httpd-fastphp5 .php Action application/x-httpd-fastphp5 /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 <Directory /usr/lib/cgi-bin> Require all granted </Directory> </IfModule>
Then, we enable all the necessary support modules:
a2enmod actions alias fastcgi
where:
actions
is needed for FPMalias
is needed to create the PHP aliasfastcgi
is the PHP FastCGI modulePHP-FPM has to be started by issuing:
/etc/init.d/php5-fpm restart
and after that Apache2 can be started by issuing:
/etc/init.d/apache2 restart
Create a PHP file containing:
<?php phpinfo();
and open it in the browser. You should see on the first screen along the top:
Server API FPM/FastCGI
which indicates that it is working.
In case you see:
Server API Apache Handler 2.0
then it is not working - most likely you have forgotten to disable the standard PHP module (with a2dismod php5).
For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.