Table of Contents

Update PHP version

To run newer PHP versions on Debian than what is provided in your stable release's official repositories, use the third-party repository maintained by Ondřej Surý. This trusted community repository provides concurrent, up-to-date PHP packages (from legacy releases up to newer builds like PHP 8.4 or 8.5) for all active Debian distributions.

Secure existing config

List existing PHP packages

This step only applies when upgrading an existing PHP setup. The following command lists all installed PHP packages with the text php in its name, shows it on screen, and writes it to a file called packages.txt. This file comes in handy at a later step when installing the PHP 8.4 packages, to ensure the same list of PHP 8.4 versions of the extensions are installed.

dpkg -l | grep php | tee packages.txt

php8.2-apcu/oldstable,now 5.1.22+4.0.11-2 amd64 [installed,automatic]
php8.2-bcmath/oldstable-security,now 8.2.33-1~deb12u1 amd64 [installed,automatic]
php8.2-bz2/oldstable-security,now 8.2.33-1~deb12u1 amd64 [installed,automatic]
php8.2-cli/oldstable-security,now 8.2.33-1~deb12u1 amd64 [installed,automatic]
php8.2-common/oldstable-security,now 8.2.33-1~deb12u1 amd64 [installed,automatic]
php8.2-curl/oldstable-security,now 8.2.33-1~deb12u1 amd64 [installed,automatic]
php8.2-fpm/oldstable-security,now 8.2.33-1~deb12u1 amd64 [installed,automatic]
php8.2-gd/oldstable-security,now 8.2.33-1~deb12u1 amd64 [installed,automatic]
php8.2-gmp/oldstable-security,now 8.2.33-1~deb12u1 amd64 [installed,automatic]
php8.2-igbinary/oldstable,now 3.2.13-1 amd64 [installed,automatic]
php8.2-imagick/oldstable,now 3.7.0-4 amd64 [installed,automatic]
php8.2-intl/oldstable-security,now 8.2.33-1~deb12u1 amd64 [installed,automatic]
php8.2-mbstring/oldstable-security,now 8.2.33-1~deb12u1 amd64 [installed,automatic]
php8.2-memcached/oldstable,now 3.2.0+2.2.0-4 amd64 [installed,automatic]
php8.2-msgpack/oldstable,now 1:2.2.0~rc2-3 amd64 [installed,automatic]
php8.2-mysql/oldstable-security,now 8.2.33-1~deb12u1 amd64 [installed,automatic]
php8.2-opcache/oldstable-security,now 8.2.33-1~deb12u1 amd64 [installed,automatic]
php8.2-readline/oldstable-security,now 8.2.33-1~deb12u1 amd64 [installed,automatic]
php8.2-xml/oldstable-security,now 8.2.33-1~deb12u1 amd64 [installed,automatic]
php8.2-zip/oldstable-security,now 8.2.33-1~deb12u1 amd64 [installed,automatic]

php.ini

Save the old: /etc/php8.2/php.ini

www.conf

Save the old: /etc/php/8.2/fpm/pool.d/www.conf

Install Sury Repository

cd /tmp
wget -q https://packages.sury.org/debsuryorg-archive-keyring.deb
apt-get install ./debsuryorg-archive-keyring.deb
. /etc/os-release
cat << EOF > /etc/apt/sources.list.d/sury-php.sources
Types: deb deb-src
URIs: https://packages.sury.org/php
Suites: $VERSION_CODENAME
Components: main
Signed-By: /usr/share/keyrings/debsuryorg-archive-keyring.gpg
EOF
apt-get update
apt-cache policy php

Install php and packages

apt install php8.4 php8.4-cli php8.4-cgi php8.4-fpm

Install custom packages:

apt install php8.4-apcu php8.4-bcmath php8.4-bz2 php8.4-cli php8.4-common php8.4-curl
apt install php8.4-fpm php8.4-gd php8.4-gmp php8.4-igbinary php8.4-imagick
apt install php8.4-intl php8.4-mbstring php8.4-memcached php8.4-msgpack
apt install php8.4-mysql php8.4-opcache php8.4-readline php8.4-xml php8.4-zip

Update configuration

Update the /etc/php8.4/php.ini with the saved /etc/php8.2/php.ini

Needed for NextCloud: /etc/php/8.4/fpm/pool.d/www.conf

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

Configuring the Default PHP Version

After installing additional PHP versions, if you want to set the OS default PHP version back to the one for your Debian release, run these commands:

update-alternatives --config php
update-alternatives --config php-cgi

Update php in

 fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;

/etc/nginx/sites-available/www.oscardegroot.nl /etc/nginx/sites-available/cloud.oscardegroot.nl

 systemctl restart nginx

https://wiki.debian.org/AdditionalPHPVersions