How to Install Latest PHP 8 on Debian 10

Install PHP 8 on Debian 10

In this article, we will have explained the necessary steps to install and setup PHP 8 on Debian 10. 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 a recursive acronym for Hypertext Preprocessor and is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. Many popular CMS and frameworks such as WordPress, Laravel, and many more are built in PHP. As of right now, PHP 8.0 is on track to be released on November 26th, 2020. The release process is in feature freeze now and we’ll have 4 betas and 5 release candidates before we get the final version (https://wiki.php.net/todo/php80 for all the dates).

Install PHP 8 on Debian 10

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 apt-transport-https lsb-release ca-certificates wget curl

Step 2. Install PHP 8 on the Debian system.

Download the SURY PPA for PHP and then set up the apt repository for it:

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

Install PHP GPG key of Sury:

curl -sSL -o /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

Then, run the following commands to install PHP 8 on Debian 10:

sudo apt install php8.0 php8.0-fpm php8.0-curl php8.0-mysqlnd php8.0-zip php8.0-mbstring php8.0-xml

In order to check the version number of your installed PHP, run the following command:

$ php8.0 -v
 
PHP 8.0.0 (cli) (built: Dec 12 2020 16:22:12) ( 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

Step 3. Install PHP extensions.

PHP extensions are compiled libraries that extend the core functionality of PHP. Extensions are available as packages and can be easily installed with apt:

sudo apt install php8.0-[module]

For example:

sudo apt install php8.0-devel

Step 4. Testing PHP.

Now, create a test PHP file called info.php in the webserver default home directory:

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

And add the following line:

<?php
phpinfo();

Once upon, open your browser and browse to the server hostname or IP address followed by the name of the file you created above:

http://localhost/info.php

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