Jan 23, 2021 2:20 PM

Installing PHP 8.x on Debian

In this article I will explain how to install the latest PHP version on the Debian operating system. Your system may not always have the latest packages for installing PHP. However, PPA (Personal Package Archive), which contains the missing packages, can help us. PHP 8.0 is the latest stable version available for installation.

This instruction was executed on operating systems: Debian 10, Debian 9.

Adding PHP repository

Let's add the PHP repository to the system. But first install the necessary software.

Before any software installation, it is recommended to update the list of repository packages by running the command in the terminal:

sudo apt-get update

Now install the necessary software:

sudo apt-get install apt-transport-https lsb-release ca-certificates

Download the public key used to verify the signature for the repository:

sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

Add the PHP repository (OndÅ™ej Surý) to the list of sources:

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

Adding PHP repository

Installing PHP 8.x

First you need to update the list of repository packages by running the command in the terminal:

sudo apt-get update

Then install PHP 8.x by running the command in the terminal:

sudo apt-get install php8.0

You can also install PHP 7.x on Debian.

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

libapache2-mod-php8.0 php-common php8.0-cli php8.0-common php8.0-opcache php8.0-readline

Installing PHP 8.x

Installing PHP 8.x extensions

The following syntax is used to install PHP 8.x extensions:

sudo apt-get install php8.x-extension

Let's install the most commonly used PHP 8.x extensions by running the command in the terminal:

sudo apt-get install php8.0-mysql php8.0-mbstring php8.0-xml php8.0-bcmath php8.0-curl php8.0-gd php8.0-zip

Installing PHP 8.x extensions

Testing PHP

Let's find out the version of installed PHP by running the command in the terminal:

php -v

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://192.168.0.101/info.php

or for localhost

http://localhost/info.php

You will see a similar page:

Testing PHP

After checking for security reasons, you need to delete this file by running the command in the terminal:

sudo rm /var/www/html/info.php

Other articles