Debian

How to Install PHP Latest Version on Debian 11 Bullseye

PHP is a powerful web scripting language used to design interactive and dynamic websites. “PHP 8.0” is the latest version of PHP which cannot be installed directly from the local repository on Debian. To install the latest PHP on Debian, an external repository will be required.

This blog is a guide on how to install the latest version of PHP, which is 8.0 on Debian.

Install PHP on a Debian 11

The content of this article is distributed under several headings which are:

Installing PHP

To install the latest PHP version on Debian, follow the below-written steps:

Step 1: First update/upgrade the repository of the system by using the below-mentioned commands:

sudo apt update
sudo apt upgrade

 

After upgrading the repository, it is recommended to reboot the system so that all the upgraded repositories can reload:

sudo reboot

 

Step 2: Now install the required dependencies using the below-written command:

sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2

 

Step 3: The latest version of PHP is available through the website sury.org, to add the sury repository run the below-written command:

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

 

Step 4: Also, import the sury repository key by using the below-mentioned wget command:

wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add -

 

Step 5: Run the update command to ensure that the repository is added successfully:

sudo apt update

 

Step 6: Once the repository is added successfully then install PHP 8.0 by running the below-written apt command:

sudo apt install php8.0

 

Step 7: To verify that the installation of the latest version of PHP is successful run the below-written command:

php -v

 

Modules/Extensions of PHP

After installing the latest PHP version, now if you want to find out all the available extensions/modules of PHP then run the below-written command:

sudo apt search php8.0-*

 

From the above list of PHP modules, if you are interested in installing any of them then follow the below-written syntax:

sudo apt install php8.0-<module name in the list>

 

For example:

sudo apt install php8.0-bcmath

 

One can also install multiple modules at a time as shown below where MySQL, XML and zip modules are installed at a time:

sudo apt install php8.0-{mysql,xml,zip}

 

To find the all the installed/loaded modules of PHP, run the below-written command:

php -m

 

PHP Testing

To test the processing of installed PHP, let’s create a new php file using the below-written command:

sudo nano newfile.php

 

Then add a text message in it:

<?php echo 'Hello Linux-hint';

 

Now to execute the created .php file, follow the below-mentioned command:

php newfile.php

 

In the output, you can see that the message text has been displayed successfully, which means php is working successfully on the system;

Conclusion

To install the latest PHP version on Debian, users first need to install some dependencies on the system. After that, they have to add the sury repository and then update the repository using the “update” command. Then, they can install PHP 8.0 from the apt command with the required PHP modules right after the repository update.

About the author

Zahra Zamir

An Electronics graduate who loves to learn and share the knowledge, my passion for my field has helped me grasp complex electronics concepts and now I am here to share them with others.