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 http://mirrordirector.raspbian.org/raspbian/ buster main contrib non-free rpi
After saving create the next file
sudo nano /etc/apt/preferences.d/php72. With the content:
Package: * Pin: release n=jessie Pin-Priority: 600
Again save. Make the system aware of this source list with
sudo apt update
Now we are ready to install PHP7 with all it’s modules:
sudo apt-get install -y -t buster php7.2-fpm php7.2-curl php7.2-gd php7.2-intl php7.2-mbstring php7.2-mysql php7.2-imap php7.2-opcache php7.2-sqlite3 php7.2-xml php7.2-xmlrpc php7.2-zip php-apcu
When done check it with
php -v it should show a PHP 7.2. (or higher).
Now we need to add a few fpm things for nginx to work properly.
sudo nano /etc/php/7.2/fpm/conf.d/90-pi-custom.ini
cgi.fix_pathinfo=0 upload_max_filesize=64m post_max_size=64m max_execution_time=600
Now PHP is ready to use
You might want image optimization.
We have installed php-gp for that. But that is not enough.
sudo apt install -y optipng gifsicle libjpeg-progs