How to Install PHP 8 on Debian 11

Install PHP 8 on Debian 11

In this article, we will have explained the necessary steps to install PHP 8 on Debian 11. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

PHP is one of the most used server-side programming languages. PHP comes with many powerful features includes a Just-in-time (JIT) compiler, attributes, named arguments, and more. Many popular platforms including, WordPress, Magento, Drupal, and Joomla are based on PHP.

Install PHP 8 on Debian 11

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo apt update
sudo apt upgrade
sudo apt install lsb-release ca-certificates apt-transport-https software-properties-common

Step 2. Install PHP 8 on Debian 11 system.

Now download the GPG key to your system:

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

Once you are done, update the repository with the following command and install it:

sudo apt update
sudo apt install php8.0

Confirming the installed version:

php -v

Result:

PHP 8.0.10 (cli) (built: Aug 26 2021 16:06:19) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.10, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.10, Copyright (c), by Zend Technologies

Step 3. Install PHP Modules.

You can install other PHP 8 modules using the command:

sudo apt install php8.0-<extension>

Example:

sudo apt install php8.0-{gd,pgsql,soap,mysql,cli,common,imap,ldap,xml,fpm,curl,mbstring,zip}

Step 4. Testing PHP Processing.

Create an info.php file inside the Apache web root directory to test the PHP version:

nano /var/www/html/info.php

Add the following line:

<?php phpinfo(); ?>

Save the file, open your browser of choice, and visit http://your_server_ip/info.php

Install PHP 8 on Debian 11

That’s all you need to do to install the PHP on Debian 11 (Bullseye). I hope you find this quick tip helpful. For further reading on Debian’s system, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.