It is available for all OS. The latest version of PHP is version 8 and in this article, we will discuss the installation of PHP on the Debian 11 (Bullseye) Linux system.

Prerequisites

First, update all the packages of the system by below-mentioned command: After updating packages, now install the dependencies required by the below-mentioned command:

Step 1 – Enable SURY Repository

The following step is to integrate the SURY repository into our system. SURY is a Debian-based third-party PHP repository that bundles PHP software, run the following command to add SURY repository: Importing the GPG key for the repository by the below-mentioned command:

Step 2 – Installing PHP on Debian 11

Now again update packages for syncing them with the recently added SURY repository before installing php: The SURY repository contains PHP 8.1, 8.0, 7.4, 7.3, 7.2. 7.1, 7.0 & PHP 5.6. As the latest stable version of PHP is 8.0, but a large number of websites still required PHP 7. You can install any of the required PHP versions on your system.

Install PHP 8.1 on Debian sudo apt install php8.1 Install PHP 7.4 on Debian sudo apt install php7.4 Install PHP 5.6 on Debian sudo apt install php5.6

Replace version 8.1, 7.4 or 5.6 with the required PHP version to install on your Debian system. Even you can install multiple PHP versions on a single Debian system.

Step 3 – Installing PHP Extension

Moreover, we can also add the php extension by below-mentioned syntax: Replace [extension] with the extension you want to install, if you want to add multiple extensions then include them in braces, I am going to install “php-mbstring, php-cli, php-xml, php-common, and php-curl” by running the below-mentioned command: Users have installed different PHP version, need to replace 8.1 with required PHP versions.

Step 4 – Checking PHP Version

Now after installation verify that the correct version of PHP is installed by checking the version number by the below-mentioned command:

Step 5 – Switch Between PHP Versions

You can use update-alternatives command to set the default PHP version. Use this tutorial to read more details about switching PHP version for CLI and Apache. The above output shows all the installed PHP versions on your system. Input a selection number to set default PHP version for command line.

Conclusion

PHP is a free, server-side programming language also used with HTML programming language for creating dynamic websites. It is available for all operating systems but in this article, we discuss its installation on Debian 11 (Linux OS) Bullseye. You will successfully install PHP on Debian 11 after going through this guide.