How To Install PHP 8 on Debian 11

Install PHP 8 on Debian 11

In this tutorial, we will show you how to install PHP 8 on Debian 11. For those of you who didn’t know, PHP is an open-source, general-purpose scripting language that is especially suited to web development but has also been used as a general-purpose programming language. The latest PHP release to date is the 8 series. PHP 8 is a significant update of the PHP language. It contains many new features and optimizations, including named arguments, union types, attributes, constructor property promotion, match expression, null safe operator, JIT, improvements in the type system, error handling, and consistency.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you through the step-by-step installation of PHP 8 on a Debian 11 (Bullseye).

Install PHP 8 on Debian 11 Bullseye

Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt commands in the terminal:

sudo apt update
sudo apt upgrade
sudo apt install curl wget gnupg2 ca-certificates lsb-release apt-transport-https

Step 2. Installing PHP 8 on Debian 11.

Now we add the SURY repository to your system:

sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'

Then, install PHP 8.0 using the following command below:

sudo apt update
sudo apt install php8.0

Additionally, the necessary packages will be installed, some of which are standard PHP 8.x extensions:

sudo apt install php8.0-common php8.0-gd php8.0-ldap php8.0-odbc php8.0-xsl php8.0-apcu php8.0-curl php8.0-gmp php8.0-opcache php8.0-mbstring php8.0-pgsql php8.0-imagick php8.0-memcached php8.0-bz2 php8.0-ds php8.0-imap php8.0-cgi php8.0-mysql php8.0-cli php8.0-fpm php8.0-xml

After the installation has been completed, you can confirm the installation using the following command:

php -v

Step 3. Testing PHP.

Now we create a test file that will return information about our server by running the command in the terminal:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Let’s make sure that the server correctly displays the content generated by the PHP script by opening this page in the browser: http://localhost/info.php, If the PHP info page is rendered in your browser then everything looks good and you are ready to proceed further.

Congratulations! You have successfully installed PHP. Thanks for using this tutorial for installing the latest version of PHP 8 on Debian 11 Bullseye. For additional help or useful information, we recommend you check the official PHP website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!