Installing PHP 8.2 on Rapsberry Pi

In this guide we will install php 8.2 and do very basic tweaks

Note: this post call also be used to install php7.0, php7.1, php7.2, php7.3 , php7.4 and php8.0just change every reference to 7.x/8.0.
Only php8.0 and higher are still supported

Check if you can install php8.2

To check if php8.2 is available run: sudo apt install --dry-run php8.2
If you get an error continue, if you don’t get an error continue to actual install php

As the php version is not available
We are going to create a new source for php. We do this with the following 3 commands.

sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ buster main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt update

Actual install php

Now we are ready to install php8.2 with all modules we need:

sudo apt install -y php8.2-common php8.2-fpm php8.2-cli php8.2-curl php8.2-intl php8.2-mysql php8.2-gd php8.2-sqlite3 php8.2-mbstring php8.2-zip php8.2-readline php-pear imagemagick php-imagick

*note: for php7 add php7.4-json php7.4-opcache in php8 and higher these packages are part of core php

When done check it with php -v it should show a php 8.2.0 or higher.
Now we need to add a few fpm things for nginx to work properly.
Create a extra config file sudo nano /etc/php/8.2/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 php8.2-fpm reload

Now PHP is ready to use.

To check configuration run php -i To see the phpinfo in the browser check the nginx guide, as php needs to be connected to nginx.

Extra’s

If you’re interested in installing some php applications you might want to follow these other guides. to install.