With latest version of Raspbian being based on Debian Jessie, this still comes with PHP 5.6 by default. Since PHP 5.6 reaching its end of life, and only security updates support starting tomorrow, it's time to start looking at the newer versions. PHP 7.0 was released last december in 2015 but is still not merged in the stable branch. Luckily there's a little workaround for this issue!

To install PHP 7 we must tap into the testing branch of Raspbian. Start with opening /etc/apt/source.list with your favorite editor.

sudo nano /etc/apt/sources.list

And add this line at the end of the file.

deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi

Now what we don't want is that every package is updated or installed from the stretch (testing) branch. To do this we can set some preferences that we want all packages to be selected from Jessie by default. Open up the following file /etc/apt/preferences.

sudo nano /etc/apt/preferences

And add the following contents to it.

Package: *
Pin: release n=jessie
Pin-Priority: 600

Save the file and run an update.

sudo apt-get update

Now if you want to install something from the testing branch, you can do this using the following format.
For example, installing the PHP 7 cli package can be done like this.

sudo apt-get install -t stretch php7.0-cli

And that's pretty much it, enjoy! Since this most likely my last post of 2016, happy new year! 🥂

Comments (3)

  • Gravatar Thibault

    Damn neat guide! I remember trying to set this up since v7 is included in the Sid release but bumped into numerous issues along the way. Seems like a breeze using this guide, thanks Wouter!

  • Gravatar Kenny

    And for those of us who have no idea what the heck PHP is?

  • Gravatar Wouter

    @Kenny: If you don't use PHP on your Raspberry Pi, don't worry, you don't need it ;-)!

Post comment