About

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.

Installing

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

Configuring

Next, we create or overwrite the file at /etc/apache2/mods-available/fastcgi.conf with the following contents:

fastcgi.conf
<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>

Enabling the Modules

Then, we enable all the necessary support modules:

a2enmod actions alias fastcgi

where:

  • actions is needed for FPM
  • alias is needed to create the PHP alias
  • fastcgi is the PHP FastCGI module

Starting Services

PHP-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

Checking the Configuration

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).

Fixing Common Issues


linux/debian/apache_fastcgi.txt ยท Last modified: 2022/04/19 08:28 by 127.0.0.1

Wizardry and Steamworks

© 2025 Wizardry and Steamworks

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.