Running PHP5.6 and PHP7.0 concurrently with NGINX

I run an NGINX server with PHP 7.0 and recently needed to host an app that did not support PHP 7.  Rather than spin up another server, I looked at running 5.6 and 7.0 on the same machine.  As it turns out, it isn’t too difficult thanks to the work of Ondřej Surý. He’s created a repository of co-installable PHP 5.6 and 7.0 packages. Here’s how to get this setup on Ubuntu 16.04 LTS.


First, off, this only works for UTF-8, so you need to make sure you have a UTF-8 locale installed

You should see at least one line indicating a UTF-8 locale.  In my case I see “en_US.utf8”.  If you see this, you can skip the next step.

Do this next step only if you didn’t see a UTF-8 locale in the previous step.  This will generate a UTF-8 locale. (Substitute your specific locale for en_US)

Next, ensure that you have the add-apt-repository command by installing the following package

Install the repository and update

Just in case any old PHP 5 components are installed, remove them

Install the new co-installable packages for PHP 5.6 and PHP 7.0

Optionally, you may want to also install these typical packages depending on your needs.

And that’s pretty much it.  Using individual site configuration files for each website you can specify PHP 7.0 for some apps and PHP 5.6 for others.