Projekt

Allgemein

Profil

Aktionen

Install PHP8 on Debian 10 Debian 11

Based on linuxshelltips but using key only for sury library.

Current best practice is not to install keys for extra repositories as general apt keys but storing them in /usr/share/keyring and authorizing repositories explicitly with the corresponding key.

Also there's no need to uninstall PHP 7. several PHP versions can coexist.

So, let's start.

Have your Debian up to date:

sudo apt update && sudo apt upgrade -y

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

Get and store Sury's keys:

wget -qO - https://packages.sury.org/php/apt.gpg|gpg --dearmor | sudo tee /usr/share/keyrings/sury-php.gpg > /dev/null

Config Sury's repository:

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

Use the newly installed repository (most times it also upgrades the currently installed PHP 7.4):

sudo apt update && sudo apt upgrade -y

If the meta packege php is installed, this upgrade switches to the most current PHP version (i.e 8.2 in February 2023)

Now you can install any supported PHP version:

sudo apt install php8.1

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 

changing PHP versions

The default PHP version (used by /usr/bin/php) can be interactively selected by:

sudo update-alternatives --config php

Von Martin Meier vor mehr als 1 Jahr aktualisiert · 2 Revisionen