Home Debian How to Install Latest PHP 8.1 on Debian 11/10

How to Install Latest PHP 8.1 on Debian 11/10

Debian is a secure and stable Linux-based operating system distribution offering unmetered server performance to web-based applications. Debian 11Bullseye” is profiled with improved security, exFAT file systems support, and multiple languages support as features that go hand in hand with numerous web-based applications.

Among the features and improvements paraded in PHP 8, the JIT compiler for web apps is most notable. Its benefits include better numerical code performance, better PHP web application code execution and performance, and potentially fast PHP code due to supported C to PHP code migration.

Other notable new/improved features in PHP 8 include strict type checks, especially for Bitwise/Arithmetic operators, saner numeric strings, nullsafe operator, named arguments, weak maps, throw expression, and constructor property promotion.

This article will give a walk-through on installing PHP 8 on Debian 11/10.


Have root/sudoer user privileges on the Debian 11 system you are using.

Installing PHP 8 on Debian Linux

Updating your Debian system ensures it stays in the best-performing state on top of applying the needed security patches.

$ sudo apt update && sudo apt upgrade -y 

If you have older PHP versions like 7.x, you might want to uninstall it to primarily benefit from the features and improvements attached to PHP 8.

$ sudo apt remove --purge php*
Remove PHP in Debian
Remove PHP in Debian

Next, install the required PHP 8 installation dependencies and also configure the UFT-8 Unicode standard.

$ sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2   
$ sudo locale-gen en_US.UTF-8

Now add the Ondřej Surý PPA repository, which will be responsible for tracing, retrieving, and installing the latest PHP version on your Debian 11 system.

$ echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/sury-php.list
$ sudo wget -qO - https://packages.sury.org/php/apt.gpg | sudo gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/debian-php-8.gpg --import
$ sudo chmod 644 /etc/apt/trusted.gpg.d/debian-php-8.gpg

After adding a repository, update the Debian system to recognize the inclusion of the Ondřej Surý PPA repository. Also, if future PHP versions are released, upgrading to them will require a simple Debian 11 system update command like the one below:

$ sudo apt update && sudo apt upgrade -y

Finally, install PHP 8.1 on Debian 11.

$ sudo apt install php8.1
Install PHP in Debian
Install PHP in Debian

Confirm the installed php version.

$ php --version 
Check PHP in Debian
Check PHP in Debian

To install other PHP extensions, reference the syntax:

$ sudo apt install php8.1-name_of_extension

For instance, to install a php-fpm extension, we will execute the command:

$ sudo apt install php8.1-fpm 

This article has taught us how to install PHP and any of its associated extensions on Debian 11. You are now ready to pursue your web-based applications/projects.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

2 thoughts on “How to Install Latest PHP 8.1 on Debian 11/10”

  1. In the end, I get this:

    The following packages have unmet dependencies:

    php8.1-fpm : Depends: php8.1-cli but it won’t install
    Depends: libpcre2-8-0 (>= 10.38) but 10.36-2+deb11u1 will be installed

    I have been trying for a long time to install php8 on Debian 11 bullseye but it doesn’t work.

    Updates Sury repositories fine but doesn’t install php8

    • @Cloud,

      Try these commands to fix the error, which will remove php, install libpcre package, and finally you able to install PHP8.1.

      $ sudo apt remove php
      $ sudo apt install libpcre2-8-0
      $ sudo apt install php8.1

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.