Upgrade or Install PHP 8.2 on Debian running Apache2
This tutorial show you how to install or upgrade PHP 8.2 quick and easy for Apache web server running on Debian 9 or Debian 10 and Debian 11. PHP is the widely used server scripting language for dynamic and interactive websites and content management systems.
5 steps to perform PHP 8.2 for Apache2 on Debian.
1. Updating Debian as root
$ su -
$ apt update
$ apt upgrade -y && reboot
2. Add SURY PHP PPA Repository
SURY is a third-party repository that offers current PHP versions for Debian GNU/Linux, which is added as root.
$ apt -y install lsb-release apt-transport-https ca-certificates wget
$ wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
$ echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list
3. Installing PHP 8.2 on Debian
$ apt update
$ apt -y install php8.2
$ update-alternatives --set php /usr/bin/php8.2
More than one PHP version can be installed on the system, run update-alternatives --set php [version]
to enable a Version.
4. Install Important Modules for PHP 8.2 on Debian
$ apt -y install php8.2-cli php8.2-curl php8.2-gd php8.2-intl php8.2-mbstring php8.2-mysql php8.2-opcache php8.2-readline php8.2-xml php8.2-xsl php8.2-zip php8.2-bz2
5. Making PHP 8.2 module for Apache available
$ apt -y install libapache2-mod-php8.2
$ systemctl reload apache2
Finish! the installation is done. If you want to know which installed PHP version and modules are actually available, the next section shows.
Check the current PHP version
$ php -v
PHP 8.2.3 (cli) (built: Feb 14 2023 16:53:07) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.3, Copyright (c) Zend Technologies
with Zend OPcache v8.2.3, Copyright (c), by Zend Technologies
Show current PHP configuration
The current PHP settings are displayed by creating a .php-file with the following content, to output the detailed settings in the web browser.
<?php
phpinfo();
?>
Save the file as phpinfo.php
in the “/html” directory. Then open the newly created .php-file in a web browser.
http://my-domain/phpinfo.php
The system-wide PHP settings can be found under the path /etc/php
, for modification using Apache 2 edit the php.ini
file.
$ vi /etc/php/8.2/apache2/php.ini
If you do not see the installed php version, may the apache php module need to change to the desired version, run the apache helper command in the terminal, replace the version you have instead, like here php.7.4 in this example.
$ a2dismod php7.4
$ a2enmod php8.2
$ systemctl restart apache2
Verify the running php module with view the phpinfo.php
from the web browser.
The PHP modules available for Apache 2 can find in the Apache web server path under /etc/apache2/mods-available
$ ll /etc/apache2/mods-available/php*
-rw-r--r-- 1 root root 855 Jul 5 2020 /etc/apache2/mods-available/php7.3.conf
-rw-r--r-- 1 root root 102 Jul 5 2020 /etc/apache2/mods-available/php7.3.load
-rw-r--r-- 1 root root 855 Dec 20 22:32 /etc/apache2/mods-available/php7.4.conf
-rw-r--r-- 1 root root 102 Dec 20 22:32 /etc/apache2/mods-available/php7.4.load
-rw-r--r-- 1 root root 855 Dec 20 22:32 /etc/apache2/mods-available/php8.2.conf
-rw-r--r-- 1 root root 101 Dec 20 22:32 /etc/apache2/mods-available/php8.2.load
Disable an Apache 2 module with a2dismod
, use a2enmod
to enable. The apt info
command provides information about module information.
$ apt info libapache2-mod-php8.2
Specify the desired php version of a website in apache .htaccess file.
Action php /cgi-php82/php
AddHandler php82 .php
I think it should be „update-alternatives“ not „update-alternative“
The repository ‚https://packages.sury.org/php stretch Release‘ does no longer have a Release file.
N: Updating from such a repository can’t be done securely, and is therefore disabled by default.
On debian 9 I’m getting 404 from apt update after adding https://packages.sury.org/php to my source list.