User Tools

Site Tools


PHP7.2 with Nginx install for RPi3

1.0 --- RPi3 Preparation

Raspbian Updates

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get upgrade
sudo rpi-update
sudo reboot

Raspbian Configuration

sudo raspi-config

2.0 --- PHP7.2 install

Raspbian being based on Debian Stretch ships with PHP 7.0 by default. This works fine, but there is a new and better supported PHP 7.2 release available. To install this newer PHP version however, we must tap into the testing branch of Raspbian, commonly known by the codename buster. We must credit a new buster.list file used by Aptitude (apt-get):

sudo nano /etc/apt/sources.list.d/10-buster.list

Add this line:

deb buster main contrib non-free rpi

Now, by adding this and referencing -t buster in our apt-get commands, it wil use the newer versions of files available in the buster release which is not considered 100% stable. To facilitate this we need to create a buster preferences file:

sudo nano /etc/apt/preferences.d/10-buster

And paste in the follwing:

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

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

Save this file and update:

sudo apt-get update

Now you are ready to install PHP 7.2 from the buster release including all the common PHP packages:

sudo apt-get install -t buster php7.2 php7.2-common php7.2-curl php7.2-gd php7.2-fpm php7.2-cli php7.2-opcache php7.2-mbstring php7.2-xml php7.2-zip php7.2-mysql php7.2-imap php7.2-cgi php7.2-pspell php7.2-recode php7.2-sqlite3 php7.2-tidy php7.2-xmlrpc php7.2-xsl php-memcache php-imagick php7.2-soap php7.2-json php7.2-readline

After this has been completed, you can quickly test to make sure things have been installed by simply typing:

php -v

You should see something like this:

PHP 7.2.9-1 (cli) (built: Aug 19 2018 06:56:13) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.9-1, Copyright (c) 1999-2018, by Zend Technologies

2.1 --- Nginx 1.13 install

We want to use a faster, more up to date, and secure version of nginx here, and luckily there's a nginx 1.13 version available in the buster release:

sudo apt-get install -t buster nginx nginx-common nginx-full nginx-doc

2.2 --- Tweak PHP7.2

Once fully installed (accept any defaults when prompted), we should now tweak our PHP 7.2 FPM pool to be better optimized:

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

And add:


Now, we want to modify our PHP 7.2 FPM pool to use our pi user and group, so edit the config file:

sudo nano /etc/php/7.2/fpm/pool.d/www.conf

And and change the user and group references:

user = pi
group = pi

Then simply restart nginx and php-fpm to ensure the new changes are picked up:

sudo service nginx restart
sudo service php7.2-fpm restart
php7_2_rpi3.txt · Last modified: 2019/01/21 18:05 by pi