Although Debian is a modern Linux-distribution based upon stability, it sometimes misses actual packages like the latest PHP-iteration.
Debian 11, released on August 14th, 2021 with version 11.0, is more than one year available at the time of writing. The latest stable PHP-version, a foundation for many web services and use cases, is currently 8.1 and was released just a little bit more than three months later, on November 25th, 2021. After nearly one year, the latest PHP-iteration you can install on a modern Debian 11-system is still 7.4. While stability is - undoubtedly - still a key feature, the improvements from PHP 8.x are numerous with the factor „performance“ in the focus. This short but sweet tutorial shall show you how to safely install PHP 8.1 on a modern Debian-11-system.
By default, there is still a rational boundary for not always going with the latest versions of software packages. Anyway, depending on your own needs and used software, the change from PHP 7.4 to 8.x brings an enormous boost for all applications that rely on the latest PHP-version and have adopted their code to take advantage of the various improvements. Enabling our system to fetch the latest package is the key factor here and to gain this, we need to add the well-known repositories of Ondřej Surý.
Adding the repository
Ondřej Surý is the main Debian packager for PHP and other packages under DEB.SURY.ORG name you may already have encountered when venturing the web. As a service to the community he provides Ubuntu-PPAs for PHP, Apache2, nginx and others that are widely used. He also runs personal Debian packaging repository located at https://packages.sury.org and is told to be the best focal point for PHP-packages away from the standard.
On our Debian system, be sure that the „curl“ package is installed. If not, a
sudo apt-get -y install apt-transport-https lsb-release ca-certificates curl
will install the desired package and additional stuff we need anyway.
Then add the key(-ring) to your system by typing
curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
and add the repository to your apt-sources:
sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
To update all repositories and some components, do a
sudo apt update && sudo apt upgrade
to ensure your system is ready for all upcoming installation tasks.
After having met all prerequisites, it’s now time to finally get familiar with PHP 8.1. To install the basic module, use the command
sudo apt install php8.1-fpm
and, after conforming your choose, the FPM-version of PHP will be installed. To check whether you did succeed or not, a
is always a good choice.
Further modules can be additionally installed depending upon your needs, for example the GD- and Curl-modules can be added via
sudo apt install php8.1-gd php8.1-curl
in no time!
With quite no efforts, we managed to install the latest iteration of PHP 8.x on our Debian 11-system. Further updates and security fixes will make use of the recently added repositories of Ondřej Surý. While the latest Ubuntu-version already brings PHP 8.1 from the scratch, older versions can also be equipped with this version by the alternative command above.