How to install PHP8.0 in Debian 10

In this post, I will explain to you how to install PHP8.0 in Debian 10.

This tutorial works on:

  • Debian 10 (buster).
  • Debian 9 (stretch).

First, you need to install the Sury sources:

# Install these packages
$ sudo apt install apt-transport-https lsb-release
# Download the signing key 
$ sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
# Add Sury repo to the sources list 
$ sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list' 
# Update the list of available packages
$ sudo apt update 

To search the packages that you can install, you have to use the command:

$ sudo apt search php8.0

To install the PHP 8.0 core, you have to use the command:

$ sudo apt install -y php8.0 php8.0-common php8.0-cli

Then you have to install the extensions. All the extensions have the prefix “php8.0”. To do this, you have to use the command:

$ sudo apt install -y php8.0-fpm php8.0-bcmath php8.0-curl php8.0-xml php8.0-gd php8.0-mbstring php8.0-mysql php8.0-readline php8.0-soap php8.0-xsl php8.0-opcache php8.0-zip

The default CLI version becomes PHP 8.0.

$ php -v
PHP 8.0.7 (cli) (built: Jun  4 2021 23:17:30) ( NTS )
 Copyright (c) The PHP Group
 Zend Engine v4.0.7, Copyright (c) Zend Technologies
     with Zend OPcache v8.0.7, Copyright (c), by Zend Technologies

If you need to change the default version to other, you can use the command:

$ sudo update-alternatives --config php
 There are 2 choices for the alternative php (providing /usr/bin/php).
   Selection    Path             Priority   Status
 0            /usr/bin/php8.0   80        auto mode
 1            /usr/bin/php7.4   74        manual mode
 2            /usr/bin/php8.0   80        manual mode 
 Press  to keep the current choice[*], or type selection number: 1
 update-alternatives: using /usr/bin/php7.4 to provide /usr/bin/php (php) in manual mode

If you check now the default PHP version, you can see that has changed to PHP 7.4:

$ php -v
PHP 7.4.20 (cli) (built: Jun  4 2021 23:17:27) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.20, Copyright (c), by Zend Technologies

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.