Install PHP 5.6 on Ubuntu 14.10

UPDATED: on Ubuntu 15 (.04 and .10), the default PHP version is the 5.6.
On Ubuntu 14, now the default PHP version is the 5.5.

Q: When will PHP 5.6 be in the official Canonical repos?
A: Probably never.

This question was answered by Marc Deslauriers, security engineer at Canonical, and make sense since Canonical point of view about server updates are: stability, security, and updates-that-doesn’t-broken-legacy-code comes first. They don’t want to update because PHP 5.5 syntax are significantly different than 5.3.

So, what we can do if we need or want newer versions than 5.3? An option is to install by compiling the source code, which is awful to maintain. Another option is to install by some rpm found on internet, which not only is hard to maintain, but also probally won’t work without some black magic and many updates to our core system libraries.

Luckly, Ondřej Surý created a non-official PPA that provides an easy way to install and maintain PHP 5.6 (or 5.5, 5.4, and so on).

Our recipe:

1. We need Apache 2.4:

check your version with:

$ apache2 -v
#Server version: Apache/2.4.10 (Ubuntu)
#Server built: Sep 10 2014 11:32:50

which means that you are using the 2.4 version. If you are using a version lower than 2.4, you need update to 2.4 (“sudo add-apt-repository ppa:ondrej/apache2”).

WARNING: if you update to 2.4, be aware that you will need to review all of your configurations since the structure and syntax are not fully compatible.

2. Remove the old PHP, install the new PPA and reinstall PHP:

$ sudo apt-get remove php5 libapache2-mod-php5
$ sudo add-apt-repository ppa:ondrej/php5-5.6
$ sudo apt-get update
$ sudo apt-get install php5 libapache2-mod-php5

3. Create a test site:

$ sudo mkdir /var/www/php-test
$ echo "" | sudo tee /var/www/php-test/index.php

4. Create the Apache .conf file (don’t forget the “.conf” extension!)

  DocumentRoot /var/www/php-test
  DirectoryIndex index.php
  AddHandler php-script .php

5. Enable the site and restart Apache:

$ a2ensite php-test
$ sudo /etc/init.d/apache2 restart

6. Open the site in your browser and check if its all working

By this way our PHP site will work as an Apache module. The other way is to do via FastCGI, which I intend to learn another day.

Close Menu