Guides 11792 Published by

The guide explains how to get PHP 8.2 on Debian 11 (Bullseye) or Debian 10 (Buster), noting that the official repositories only provide older releases, so an external source is needed. It walks through adding Ondřej Vrátil’s Sury PPA, updating the package cache and installing the core PHP 8.2 packages along with common extensions like mysql for LAMP stacks. After installation you can verify the version, purge any leftover old binaries if necessary, and then configure either Apache or Nginx to use PHP‑FPM by enabling modules or editing the upstream block and restarting the services. The post also lists common pitfalls such as missing extensions, permission issues, conflicting binaries, offers a compile‑from‑source alternative for advanced users, and invites readers to comment if they encounter problems.



How to Install PHP 8.2 on Debian 11/10 – A No‑Nonsense Guide

If you’re running a fresh install of Debian 11 (Bullseye) or the older Debian 10 (Buster) and your website needs the latest language features, this is how you get PHP 8.2 up and running without wrestling with outdated packages.

Why the official repos won’t cut it

Debian’s own repositories ship PHP 8.1 for Bullseye and PHP 7.4 for Buster. Trying to pull 8.2 from there is a dead end, because Debian doesn’t ship that version yet – it sticks to what the release team has vetted for stability. So you’ll have to add an external source or compile yourself.

Step 1: Add the “Sury” PHP repository

The Surý PPA (maintained by Ondřej Vrátil) is the gold‑standard for getting newer PHP releases on Debian. It keeps all extensions in sync with the core, so you don’t end up with mismatched modules.

sudo apt update
sudo apt install -y ca-certificates lsb-release apt-transport-https wget

wget https://packages.sury.org/php/apt.gpg
gpg --dearmor -o /etc/apt/trusted.gpg.d/sury-php.gpg apt.gpg

echo "deb https://packages.sury.org/php/ $(lsb_release -cs) main" \
  | sudo tee /etc/apt/sources.list.d/sury-php.list

Why this matters: The lsb_release command pulls the codename (bullseye or buster) so your machine grabs the right package set. Skipping the GPG step would leave you with a broken repo and an error when you try to update.

Step 2: Update the cache and install PHP 8.2
sudo apt update
sudo apt install -y php8.2 php8.2-cli php8.2-fpm php8.2-mysql

I usually drop in php8.2-mysql because that’s a common extension for LAMP stacks, but feel free to cherry‑pick what you need. The -cli and -fpm packages let you run PHP from the command line or as an HTTP backend respectively.

Why this matters: Installing php8.2-fpm instead of the older mod_php keeps Apache leaner and lets Nginx take over if that’s your flavor.

Step 3: Verify the installation
php -v

You should see something like:

PHP 8.2.x (cli) (built: ...)
Copyright (c) The PHP Group
Zend Engine v4.2.x, Copyright (c) Zend Technologies

If php still points to 7.4 or 8.1, check that you didn’t have an older version lingering:

sudo apt purge -y php*
sudo apt autoremove
# then repeat Step 2

Why this matters: A leftover old binary can cause subtle bugs, especially when scripts use features introduced in PHP 8.

Step 4: Configure your web server

For Apache:

sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.2-fpm
sudo systemctl reload apache2

For Nginx, add or update the upstream block in /etc/nginx/sites-available/default:

upstream php {
    server unix:/run/php/php8.2-fpm.sock;
}
server {
    listen 80;
    root /var/www/html;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass php;
    }
}

Then:

sudo systemctl restart nginx

Why this matters: These steps tell the web server to hand PHP files off to the FPM socket, which is how modern deployments stay fast and scalable.

Common pitfalls I’ve seen
  • Missing extensions – If your app relies on pdo_sqlite or gd, you’ll have to install them explicitly: sudo apt install php8.2-pdo_sqlite php8.2-gd.
  • File permission headaches – Don’t let the web server try to write to files it can’t touch; set www-data ownership for /var/www/html and give directories 755.
  • Conflicting PHP binaries – When you upgrade from 7.x to 8.2, old scripts may still invoke /usr/bin/php, which could resolve to the older version if the symlink hasn’t been updated. Run which php after each step to double‑check.
What if you want to compile PHP yourself?

If you need a custom patch or want the bleeding edge, grab the source from https://www.php.net/downloads.php and follow the configure, make, make install dance. That’s a whole other rabbit hole and not worth the hassle unless you’re building an experiment.

Wrap‑up

Now your Debian box is speaking PHP 8.2, ready to run modern frameworks or just serve static pages with lightning speed. If you hit any snags, drop a comment – I’ve seen folks stumble over missing php.ini tweaks more often than on the whole installation process.