Installing PHP7.3 on a Rapsberry Pi

Note: this post call also be used to install php7.2, just change every 7.3 reference to 7.2.

Default rasbian still ships with php7.0 even though that version in not supported any more. We will install the latest php 7.3. But because this is not the default we will need to do a few extra tweaks.

Add newer source

Let’s create a new source list: sudo nano /etc/apt/sources.list.d/10-buster.list.
In that file add.

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

After saving create the next file sudo nano /etc/apt/preferences.d/10-buster.
In that file add.

Package: *
Pin: release n=stretch
Pin-Priority: 900

Package: *
Pin: release n=buster
Pin-Priority: 750

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

sudo apt update

Actual install php

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

sudo apt install -y -t buster php7.3-fpm php7.3-curl php7.3-gd php7.3-intl php7.3-mbstring php7.3-mysql php7.3-imap php7.3-opcache php7.3-sqlite3 php7.3-xml php7.3-xmlrpc php7.3-zip php7.3-bcmath php-apcu

When done check it with php -v it should show a PHP 7.3.. Now we need to add a few fpm things for nginx to work properly. Create a extra config file sudo nano /etc/php/7.3/fpm/conf.d/90-pi-custom.ini.
And add:

cgi.fix_pathinfo=0

upload_max_filesize=64m
post_max_size=64m
max_execution_time=600

Finally reload php

sudo service php7.3-fpm reload

Now PHP is ready to use

Extra’s

You might want to follow these instructions to install. wp-cli, composer, image compression support in php