Installing PHP7.1 on a Rapsberry Pi

To get a big performance boost we will use PHP 7.1 instead of the older 5.6 which Rasbian still uses by default. But because this is the default we will need to do a few extra tweaks.

In the file sudo nano /etc/apt/sources.list at the end we add:

deb buster main contrib non-free rpi

After saving create the next file sudo nano /etc/apt/preferences. With the content:

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

Again save. Make the system aware of this source list with

sudo apt-get update

Now we are ready to install PHP7 with all it’s modules:

sudo apt-get install -y -t buster php7.1-fpm php7.1-curl php7.1-gd php7.1-intl php7.1-mcrypt php7.1-mbstring php7.1-mysql php7.1-opcache php7.1-sqlite3 php7.1-xml php7.1-zip php-apcu

When done check it with php -v it should show a PHP 7.1.8 (or higher).
Now we need to add a few fpm things for nginx to work properly.

sudo nano /etc/php/7.1/fpm/conf.d/90-pi-custom.ini

And add:



Save and next open sudo nano /etc/php/7.0/fpm/pool.d/www.conf Search for $HOSTNAME and change.

;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp

remove the ‘;’ at the start

env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp


Apply these changes sudo service php7.1-fpm reload

Now PHP is ready to use

Leave a Reply

Your email address will not be published. Required fields are marked *