How to install PHP 8.2 on Debian 11

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Hello, friends. In this post, you will learn how to install PHP 8.2 on Debian 11. PHP is a programming language for the web and is the most popular of them all.

Although Debian 11 is a very robust system, this is achieved by including somewhat outdated software and now that Debian 11 is almost two years old, many packages may already be obsolete. A case in point would be PHP.

Debian 11 includes by default version 7.4 of PHP that although it enjoys support and is good, some applications already require higher versions. So, here we have the problem.

Install PHP 8.2 on Debian 11

First, connect via SSH to your server and update it

sudo apt update
sudo apt upgrade

As PHP 8.2 is not in the official Debian 11 repositories, then you have to add one to ease the process.

First install some necessary packages

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

Then, add the GPG key of it

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

Now add the repository in question

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

Next, refresh the repositories and install PHP 8.2

sudo apt update
sudo apt install php8.2 apache2 php8.2-mbstring libapache2-mod-php8.2

Install PHP 8.2 on Debian 11
Install PHP 8.2 on Debian 11

And as many as you want.

Testing PHP 8.2 on Debian

To know if the whole process was successful, you can then install a web server like apache and test it.

Now, open the ports 80 and 443 in the firewall and create a file in the Apache root

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

And add some PHP code

<?php
phpinfo();
?>

Save the changes and close the editor and to apply the changes

sudo systemctl restart apache2

Open your web browser and go to http://localhost/test.php or if it was on a remote server http://your-server/test.php.

PHP 8.2 working on Debian 11
PHP working on Debian 11

And you are done!

Conclusion

PHP 8.2 is a recent version of PHP that will be with us for a while longer. So, it is worth to have it and update the version that already comes with the system.

I hope you liked this post and you can use it.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook