Debian

How to Install PHP on Debian 12?

how to install php on debian 12

PHP is a popular, general-purpose, cross-platform script language suited for web development. Web developers use PHP to interact with databases to create content. It is implemented on the server side embedded in HTML. In this article, the installation steps of PHP on the Debian 12 (Bookworm) system are discussed.

How to Install PHP on Debian 12?

To install PHP on Debian 12, users can utilize the APT package manager. For this, follow the step-by-step procedure below:

Step 1: Launch Terminal

The first step is to launch Terminal. It can be launched either by using the shortcut Ctrl+Alt+T or by using the Application launcher.

All applications, system components, and files installed on the system are placed in the Application Launcher. Terminal can be launched by application launcher by pressing the Activities button in the left corner of the screen, then by typing “Terminal” in the search bar and by selecting the Terminal icon:

The following screenshot shows how the Terminal Application looks like on Debian:

Step 2: Update APT Sources/Packages

It is highly recommended to make sure that all existing packages are up to date before installing any software. This is to avoid dependency issues. We can do that by running the following command as root or user with sudo privileges:

$ sudo apt update

Step 3: Install PHP

We will install PHP by using apt, i.e., the default package manager of Debian, by running the following command:

$ sudo apt install php

The installation process will start. Press “Y” at the prompt to continue with the installation process. The installation will be completed once the above command is executed.

Step 4: Verify Installation

We can verify if the PHP is installed correctly by checking its version with the following command:

$ php -v

Step 5: Install PHP Extensions

We can install PHP extensions/modules at any time whenever we require one by replacing the extension/module name instead of php-extension. The general syntax of installing PHP extension is as follows:

$ sudo apt install php-extension1 php-extension2 php-extension3

PHP extensions can be installed by running the following command:

$ sudo apt install php php-curl php-fpm php-bcmath php-gd php-soap php-zip php-curl php-mbstring php-mysqlnd php-gd php-xml php-intl php-zip

The above command will install PHP extensions: php-curl, php-fpm, php-bcmath, php-gd, php-soap, php-zip, php-curl, php-mbstring, php-mysqlnd, php-gd, php-xml, php-intl, and php-zip.

Additionally, we can run the following command to check all the PHP modules:

$ php -m

How to Uninstall PHP on Debian 12?

If in case, we need to completely uninstall PHP (configuration and/or data files of PHP) from our system then we can run the following command with the PHP version (We can check the version as described in Step 4):

$ sudo apt purge PHP8.2

Press “Y” at the prompt to continue with the uninstallation process.

We can then continue with the following command to remove the dependencies:

$ sudo apt-get autoremove

Press “Y” at the prompt to continue with the uninstallation process. After executing the purge and autoremove commands, PHP will be completely uninstalled.

Bonus Tip: How to Use Previous Versions of PHP?

If we want to use previous versions of PHP e.g., PHP 7.x/8.0/8.1 along with the latest version, i.e., PHP 8.2, we need to install Sury Apt (https://deb.sury.org/), which is a third party repository that provides PHP packages. By installing Sury Apt, we can have multiple versions of PHP (added from Surry Apt) installed in our system and we can switch between these versions.

Conclusion

To install PHP on Debian 12, users can utilize the APT package manager. Additionally, this article also discussed the extensions of PHP. PHP is a widely used language for web development. This article discussed how to install the latest version of PHP., (i.e., PHP 8.2) on Debian 12 (Bookworm) systems.

 

Similar Posts