Update PHP 5.5 to PHP 7 or PHP 5.6 on Ubuntu

19th of October 2016–14:30PM

Hi everyone :) for all the people coming from the web … you’ll find a blank page … I know it and I beg your pardon … The only way for me to publish articles is to schedule them, and this will force me writing stuff… otherwise I will postpone them indefinitely… So I forget I had this simple tutorial scheduled for today. It’s a simple one, but is a thing a faced recently so why not sharing ?

In a couple of hours will be available on Medium, 

19th of October 2016–15:00PM

PHP and version updates

The problem with PHP is that people (and I’m one of that people) tend to not take it up to date with latest versions… I know guys which still use php 5.2 in production and they still don’t know what namespaces (from PHP 5.3) are and why they are useful for… This is just for fun, I don’t want to start talking about this topic… it will lead very quickly to a rant or worse to a flame.

I’m not interested, at the moment, of talking about development in general or about best practices.

I’m just telling you, that I’m not used to take PHP updated on our production servers… (ok hackers :) now is updated to the last version so don’t start see a challenge..).

Ubuntu and LTS

The maintainer of Ubuntu, and about versions I’m talking about LTS , have a very “protective” approach to update versions inside packages. I have to admit that I agree this approach, only stable and “super” tested packages.

If you have special needs you can use PPA … and in our specific situation, Ondřej Surý is our Lord! I mean Ondřej has done an incredible job, during the last years, maintaining PPA with PHP latest versions always available.

If you have a look at his PPA page you’ll find many many packages maintained by him :

Packages maintained by Ondřej Surý

and if we had a look to PHP

The first php 5.4, if I’m not wrong, has been created during 2013.

Let’s talk about a new update to PHP 5.6 and 7.0 packages.

UPDATE UBUNTU LTS 14.04.5 from PHP 5.5 to the WORLD !!

the bad news is that if you are already using Ondřej PPA to take php update, this has changed… what does it mean ? Well it’s pretty easy : in a normal world it will suffice :

sudo apt-get udpate
sudo apt-get install php5

Bad news buddies, the PPA has been deprecated, so you have to remove the old ones.. and install a new PPA from Ondřej.

PHP 5.6 and PHP 7.0 and 7.1

The good news is that the new PPA has not been designed to support only one version but you can install php 5.6.x or PHP 7.0.x or PHP 7.1.x. Now the PPA is more flexible! Thank you again Ondřej!

What we should do now ?

I’ve prepared a sets of BASH scripts to update your VM to PHP5.6 or to PHP7.0, you can find them on my GitHub repo dedicated to these tutorials :)

Let’s go deep to our tutorial

sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php5.6-fpm

first add the new PPA, pay attention : due to a bug with non UTF-8 locales place LC_ALL=C.UTF-8 before adding the new repo.

sudo update-alternatives — set php /usr/bin/php5.6
sudo service php5-fpm stop
sudo cp /etc/php/5.6/fpm/pool.d/www.conf  ...
sudo cp /etc/php5/fpm/pool.d/www.conf ...
sudo cp /etc/php5/fpm/php.ini ...

switch to php5.6 executable, stop the old php5-fpm service copy your old php.ini and www.conf to the new dirs.

The BIG CHANGE is the PHP path… so if you simply add the new repo update to php5.6 and restart… nothing will work properly…. Why ???

“I’m so scared… my production HTTP env stop working”

the old package installed PHP here :


the new one


That’s why I’m copying my old php.ini and www.conf files from the old path the the new one… beware of doing this kind of operation, check you config option won’t brake php5.6 :)

Then disable the old rc.d for php5 and stop php5.6 fpm

sudo update-rc.d php5-fpm disable
# restart PHP 5.6 FPM to read the new configuration
sudo service php5.6-fpm stop

Update your php extenstions, and the remove the old php5 libraries and the old php ppa.

sudo apt-get — purge remove php5-common
sudo add-apt-repository — remove ppa:ondrej/php5–5.6
sudo rm /etc/init.d/php5-fpm

Ok you’ve just updated PHP from the old legacy PHP 5.5 to the old new PHP 5.6 or better php 7.0 or 7.1 !!! Well done.

This is just a quick tutorial on what you have to expect if you decide to update you php 5.5 to php 5.6 or to php 7.x. It’s based on my experience updating our productions environment from php 5.5 to php 5.6 and now to php 7.0 !! .

Before doing it in PRODUCTION check the procedure really really well!

Before doing it in PRODUCTION check also Ondřej’s Migration Guide which cover all the migrations aspects.


A quick talk about update-alternatives

from the Ubuntu man page

It is possible for several programs fulfilling the same or similar functions to be installed on a single system at the same time. For example, many systems have several text editors installed at once. This gives choice to the users of a system, allowing each to use a different editor, if desired, but makes it difficult for a program to make a good choice for an editor to invoke if the user has not specified a particular preference.

In this way you can maintain multiple program versions on the same distribution, this could be done also with PHP, and it’s what you can do with PHP installed from this PPA. so Enjoy!

sudo update-alternatives --list php

list show the alternatives available

sudo update-alternatives --config php
with — config option you will be prompted in an interactive mode and you can choice PHP

— config allows you to setup / config the php version desired with an interactive mode.