Apache, Fastcgi, PHP 7 on Debian Wheezy & Ubuntu 14.04

Intro: The Tyranny of Prefork

There are a lot of tutorials out there that go through the rote instructions on upgrading your Debian or Ubuntu system to use PHP 7. While I’m sure most of them are fine, they assume you’d want to use the prefork process model or event/threaded via CGI (via proxy and fcgi modules). While prefork is certainly battle-tested, it uses a ton more memory than it needs to, so I’m going to document how to upgrade an existing Fastcgi install to PHP 7.

The problem is that I’ve already set up my system with mod_fastcgi paired with the php5-fpm package, and I don’t want to fundamentally change that setup. There’s a good looking tutorial on PHP 5 + fastcgi on Linode if you aren’t already using it.

Enter PHP 7

Now, the upgrade portion. Before making any changes, it’s a good idea to keep notes about which PHP-based packages you currently have installed.

Tension / Conflict

Now add the 3rd-party repository.

If your locale isn’t set to UTF-8, there may be an error adding the repo. In that case, you’ll need to:


Many other tutorials at this point will say to install php7.0, but don’t. It assumes you’ll want to run Apache in prefork mode by installing libapache2-mod-php7.0.

When installing, you’ll see messages instructing you to enable php7.0-fpm.conf as well as mod_proxy and mod_proxy_fcgi. Ignore these messages. If you are running PHP apps that connect to MySQL, also install php7.0-mysql and the 7.0 equivalents of whatever other PHP 5 packages were installed.


Next go to the /etc/apache2/conf-available directory. Either here or in an individual virtual host file, you should have an existing set of instructions telling Apache how to deal with PHP files using the Fastcgi method. It would look something like this:

Some of the values used here may not be what you have set up, and that’s fine, as long as your values are consistently used from one line to the next. Change it to look like this:

If everything was working fine before, the only real change you’d need to make is to fix the path to the socket and add the idle timeout option. If this is a new Fastcgi install for you, save the above as /etc/apache2/conf-available/php-fpm.conf and enable it with


At this point, you just have to do some housekeeping. In case the php5-fpm package is still installed, disable or remove it. If only disabled, be sure to tell Apache not to load it with

Take a look at the files under /etc/php5/ to see if you need to copy any files or settings over to the new PHP configuration directory, /etc/php/7.0/.


PHP 7 is fast. Fastcgi is fast. Fast is good.