My notes on configuring Apache2 with FastCGI (php-fpm) on Debian

This is not intended to be a tutorial but, some of the notes I've taken while setting up FastCGI on Debian.

I followed several good tutorials at once and that got me very confused and puzzled.

I decided to run Apache2 with FastCGI because I have a server with several Joomla websites. Without FastCGI in order to be able to upload images to the sites, the directory needed to owned by the user Apache2 runs under, mostly www-data. Giving permission to that leaves you vulnerable to be hacked (and we did get hacked).

The best solution was to run FastCGI (PHP-FPM) which offers more security, since scripts are not run as the Apache user. When running multiple sites, you can even set site-specific users to run php scripts, helping prevent one site’s compromise from affecting the others, writes Alex Fornuto on one of the tutorials I followed.

These are the links to the tutorials:


This needs to be in /etc/apache2/sites-enabled/


<VirtualHost *:80>
ServerAdmin Esta dirección de correo electrónico está siendo protegida contra los robots de spam. Necesita tener JavaScript habilitado para poder verlo.
DocumentRoot /var/www/html/

<Directory /var/www/html/>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted

<FilesMatch \.php$>
# 2.4.10+ can proxy to unix socket
SetHandler "proxy:unix:/var/run/|fcgi://localhost/"

# Else we can just use a tcp socket:
#SetHandler "proxy:fcgi://"


This is what should be in the pool file:

  • Chage pool name, user, and group
  • Make sure listen matches SetHandler: listen = /var/run/

All there is left is restart php-fpm: 

  • systemctl restart php5-fpm.service

Hope this can help others.

Update Sept-10-2019:

Was experimenting using NGINX with php-fpm and everything is easy to install but was having a 502 Bad Gateway error on NGINX and found the solution here: