PHP is one of the oldest and most popular languages in computer science. It is widely used for server-side programming. The popularity is because of its active community. It was first developed in 1994 by Rasmus Lerdorf.
PHP 8.0 is the newer version of PHP language which is also usable for commercial purposes. It is a cross-platform language which means it is executable on all the major operating systems. These Operating systems include Ubuntu, Windows, macOS, etc.
Today in this article, we will teach you how to install PHP on Debian 11. We will also tell you how to uninstall PHP on Debian 11. So sit tight, be with us and learn something new.
Step1: Opening Terminal
First, we have to open the terminal by clicking on the Activities keyword at the top left corner of the screen.
Once you have clicked on the Activities keyword you’ll see a search bar. Type terminal in the search bar. After this click on the terminal.
Terminal Screen will appear.
Step2: Debian Update and Upgrade
In this step, we are going to first update our Debian packages and then upgrade them if necessary. To update the packages type the following in your terminal:
$ sudo apt update
If you see “All packages are up to date” then you don’t need to upgrade.
However, if there are some packages that need upgrading type the following command in your terminal:
$ sudo apt upgrade
Your system is now updated and upgraded.
Step3: Adding Sury APT repository
All the packages of PHP 8 are available on the following link for the Debian system:
To install the required dependency type the following command:
$ sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common
Now after this, to our Debian server we have to add PHP packages APT repository. For this purpose type the following command in your terminal:
$ echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/sury-php.list
The following output will be generated:
The next step involves importing the repository key for which we have to type the following command in our terminal:
$ wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add -
Now that we have added the repository key, let’s run the update command again to see whether the repository has been added or not:
$ sudo apt update
Step4: PHP 8 installation on Debian 11
Now that we are done with adding the repository, let us start installing PHP 8 on Debian 11.
The first command that you need to type in your terminal is the following:
$ sudo apt install php8.0
The above command will install php8.0 on your Debian 11 system.
You can also specify some other version in the above command instead of 8.0.
Now that we have installed PHP 8.0 let us check whether it was installed successfully or not. For this purpose type the following command in your terminal:
$ php -v
Step5: PHP8 Extensions
We are done with the installation of PHP on our Debian 11 system Let us now look at how to install extensions of PHP 8 on Debian. For this purpose you can use the following command:
$ sudo apt install php8.0-extention
Keep in mind that you have to replace the keyword extension from the above command and replace it with the extension you want. As an example we will install bcmath extension through the following command:
$ sudo apt install php8.0-bcmath
To see all the loaded PHP modules type the following command:
$ php -m
Uninstall/Remove PHP on Debian 11
We have successfully installed PHP on our Debian system. However, there are times where we have to uninstall the PHP from our system. Don’t worry. We are with you. Let us show you how to uninstall PHP on Debian 11.
The first step is to find out which version you have installed on your Debian 11. For this purpose type the following command:
$ php -v
Now that we know which version we are using, type the following command in your terminal to uninstall PHP:
$ sudo apt purge PHP8.0
Based on your version, you can replace the version in the above command.
Now type the following command to completely remove it from your system:
$ sudo apt-get autoremove
Now when you run the following command you won’t be able to see the version:
$ php -v
Congratulations! You have successfully uninstalled PHP from your Debian 11 system.
PHP 8.0 is the latest version of PHP and is an improvement to the PHP 7.4 version. PHP has a very huge community and most websites are developed using PHP.
In this article, we saw how to install PHP on Debian 11. The steps that were taken in installing PHP were updating and upgrading packages, adding a sury apt repository, installation of PHP 8. We also talked about how to install PHP extensions on Debian. In the end, we saw how to uninstall PHP on Debian 11.
TUTORIALS ON LINUX, PROGRAMMING & TECHNOLOGY