How to Install PHP 8 on Debian 12

PHP 8.2 is a major update of the PHP language. It contains many new features, including readonly classes, null, false, and true as stand-alone types, deprecated dynamic properties, performance improvements and more.

Update the System

Update the Debian 12 using the following command.

apt update

To Add SURY PHP PPA repository.

First, download the GPG key.

apt -y install lsb-release apt-transport-https ca-certificates 
wget -O /etc/apt/trusted.gpg.d/php.gpg

Next, add SURY to the repository.

echo "deb $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list


root@server:~# echo "deb $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list

deb bullseye main

Install PHP 8.2

Ensure the added package is up to date.

apt update

If any update is available update the system and reboot.

apt upgrade -y && reboot

To install PHP 8.2

apt -y install php8.2


root@vps:~# apt -y install php8.2
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php8.2 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap
  libcurl4 liblua5.3-0 libsodium23 php-common php8.2-cli php8.2-common php8.2-opcache php8.2-readline psmisc ssl-cert

To check the PHP version.

php -v


root@vps:~# php -v
PHP 8.2.7 (cli) (built: Jun  9 2023 07:38:17) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.7, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.7, Copyright (c), by Zend Technologies

Installing PHP Extensions

Install PHP Extensions by running the following command

apt install php8.2-<extension>

NOTE: Replace the required extensions name like below command

apt install php8.2-apcu


root@vps:~# apt install php8.2-apcu
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
The following NEW packages will be installed:

To list installed php modules/extensions.

php -m


  • PHP configurations related to Apache is stored in /etc/php/8.2/apache2/php.ini this file.

  • If you want to use PHP with Nginx you can follow this guide Click here.

This concludes our topic of installing PHP 8.2 on the Debian 12 system.