How to Install PHP 8.3 Alongside PHP 8.2 on Debian 12 with Nginx

Running multiple PHP versions on the same Debian server is straightforward. Here’s how to add PHP 8.3 while keeping your existing 8.2 installations running.

Prerequisites

bash

sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2

Add the Sury PHP Repository

bash

curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt update

Install PHP 8.3

bash

sudo apt install php8.3 php8.3-cli php8.3-fpm php8.3-common
sudo apt install php8.3-mysql php8.3-curl php8.3-gd php8.3-mbstring php8.3-xml php8.3-zip

Set CLI Default (Optional)

bash

sudo update-alternatives --config php

Select option 3 for PHP 8.3.

Check What Your Sites Are Using

bash

grep -r "fastcgi_pass" /etc/nginx/sites-enabled/

Look for lines like fastcgi_pass unix:/run/php/php8.2-fpm.sock;

Migrate a Site to PHP 8.3

Edit your nginx site config and change:

nginx

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

to:

nginx

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

Then reload nginx:

bash

sudo systemctl reload nginx

Key Points

  • Both PHP versions run simultaneously as separate services
  • Existing sites stay on 8.2 until you update their nginx config
  • CLI default only affects command-line PHP, not your websites
  • Migrate sites one at a time when ready
Scroll to Top