PHP abbreviated as “HyperText Processor”, is the open-source programming language used for Web application development. It is a scripting language, mostly used for the front end with HTML. It can be used to create e-commerce websites, manage databases, and do session monitoring.
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:
sudo apt update
After updating packages, now install the dependencies required by the below-mentioned command:
sudo apt install software-properties-common ca-certificates lsb-release apt-transport-https
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:
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
Importing the GPG key for the repository by the below-mentioned command:
wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add -
Step 2 – Installing PHP on Debian 11
Now again update packages for syncing them with the recently added SURY repository before installing php:
sudo apt update
The SURY repository contains PHP 8.2, 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.2 on Debian
sudo apt install php8.2
- 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.2, 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:
sudo apt install php8.1-[extension]
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:
sudo apt install php8.2-cli php8.2-mbstring php8.2-xml php8.2-common php8.2-curl
Users have installed different PHP version, need to replace 8.2
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:
php -v
Output:PHP 8.2.1 (cli) (built: Jan 13 2023 10:43:08) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.1, Copyright (c) Zend Technologies with Zend OPcache v8.2.1, Copyright (c), by Zend Technologies
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.
sudo update-alternatives --config php
There are 4 choices for the alternative php (providing /usr/bin/php). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/php8.1 81 auto mode 1 /usr/bin/php5.6 56 manual mode 2 /usr/bin/php7.2 72 manual mode 3 /usr/bin/php7.4 74 manual mode 4 /usr/bin/php8.1 81 manual mode 5 /usr/bin/php8.2 82 manual mode Pressto keep the current choice[*], or type selection number: 4
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.
1 Comment
Very interesting. I couldn’t get install for Debian 11. I’ve tried many. It failed every time. But it worked fine for Debian 10.