How to Install PHP 8 on Debian 9 or Debian 10

To Ensure system updated.

apt update

If any update is available update the system and reboot.

apt upgrade -y && reboot

Add SURY PHP PPA repository

First download GPG key.

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

Next, add SURY to the repository.

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

Output:

deb https://packages.sury.org/php/ buster main

Installing PHP 8

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.

apt -y install php8.0

To check the PHP version.

php -v

Output:

[email protected]:~# php -v
PHP 8.0.0 (cli) (built: Nov 30 2020 20:40:07) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.0, Copyright (c), by Zend Technologies

Installing PHP Extensions

Install PHP Extensions by running the following command.

apt install php8.0-<extension>

NOTE: Replace the required extensions name in the command

To list installed php modules/extensions.

php -m

NOTE

  • PHP configurations related to Apache is stored in /etc/php/7.4/apache2/php.ini this file.
  • If you want to use PHP with Nginx you can follow this guide Click here and if apache is installed need to disable it systemctl disable --now apache2

This concludes our topic of installing PHP 8 on the Debian 10 or Debian 9 system.