Header image

Symfony Finland
Random things on PHP, Symfony and web development

Install and run PHP 7 on Raspbian (Raspberry Pi Debian)

PHP 7 was made available on December 3rd 2015. It offers great improvements in performance and memory use, which are even more significant in resource limited environments like the Raspberry Pi. Together with MySQL 5.7 and the lightweight H2O web server it offers significant gains to performance in LAMP applications.

Debian 8 (Jessie) is locked to PHP 5.6 and will not come with an upgrade to PHP 7. Soon after launch time there is the excellent Dotdeb.org available to users of Debian.

Dotdeb is a great resource and easy to install, but for Raspberry Pi you'll need to look elsewhere. The reason is the ARM CPU; In 2015 most servers still use the x86 and x86-64 architectures (Intel and AMD processors mostly) and ARM does not have the domination here as it does in the mobile space.

Installing from APT

For one option for prebuilt APT packages for Raspbian you can look at Mati75's private Debian repository, which seems quite up-to-date, and have plenty of packages such as bz2, cgi, cli, curl, dbg, dev, fpm, gd, imap, interbase, intl, json, ldap, mcrypt, mysql, odbc, opcache, pgsql, phpdbg, pspell, readline, recode, snmp, sqlite3, sybase, tidy, xmlrpc and others.

To install PHP 7 from Mati75's repository (for Debian Jessie):

1. Add the following lines to your sources file (/etc/apt/sources.list):

deb http://repozytorium.mati75.eu/raspbian jessie-backports main contrib non-free
#deb-src http://repozytorium.mati75.eu/raspbian jessie-backports main contrib non-free

2. Add repository public key

gpg --keyserver pgpkeys.mit.edu --recv-key CCD91D6111A06851
     gpg --armor --export CCD91D6111A06851 | apt-key add -

3. Run APT update

apt-get update

4. Install PHP 7

apt-get install php7.0 php7.0-opcache

In addition you'll likely need other extensions for db access and more, they are prefixed as php7.0-xx. For installing a web server like Nginx you can follow tutorials such as Bolting on PHP with PHP-FPM. Obviously php5 packages will be php7.0 packages instead, but otherwise Debian and Ubuntu tutorials work fine with Raspbian.

Installing from source

If no the repo does not work for you, then you can look into building PHP 7 from source yourself. For initial insight on how to build PHP 7 on Raspbian read about Installing PHP 7 on Debian 8 Jessie. These configure options seem to work fine:

'./configure' '--prefix=/opt/php7' '--enable-fpm' '--with-libxml-dir=/usr/lib/x86_64-linux-gnu/' '--enable-bcmath' '--enable-exif' '--enable-intl' '--enable-calendar' '--enable-zip' '--enable-soap' '--enable-ftp' '--enable-pcntl' '--enable-mbstring' '--with-openssl' '--with-curl' '--with-pdo-mysql=mysqlnd' '--with-mcrypt' '--with-zlib' '--with-bz2' '--with-config-file-path=/opt/php7/etc/' '--with-config-file-scan-dir=/opt/php7/etc/modules/'

Read more about PHP 7:


Written by Jani Tarvainen on Monday November 30, 2015
Permalink - Tags: h2o, http2, php7, raspbian, mysql

Leave a comment

comments powered by Disqus

« HTTP/2 2015 Retrospective - Your CMS REST API should be WordPress Compatible »