Easy Steps To Upgrade PHP Version on Debian 11

In this guide, we want to teach you How To Upgrade PHP Version on Debian 11. The default PHP version that is available in Debian 11 is PHP 7.4. If you plan to update your PHP version to the latest version, you can follow the guide steps below on the Orcacore website.

How To Upgrade PHP Version on Debian 11?

To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Debian 11.

Now follow the steps below to complete this guide:

Step 1. What Is the Default PHP Version for Debian 11?

The default PHP version on Debian 11 is 7.4. To verify your current PHP version, run the command below:

php -v

At this point, in your output you should see:

Default PHP Version for Debian 11

Step 2. Remove PHP 7.4 From Debian 11

To upgrade or Update your PHP version, you must remove the current PHP version. To do this, run the command below:

sudo apt purge php7.*

After uninstalling packages, run the commands below:

# sudo apt autoclean
# sudo apt autoremove

Step 3. How To Add PHP PPA Repository in Debian?

If you are running Debian 11, the PHP 8 binary packages are only available in the Ondřej Surý PPA repository. First, install the required packages with the command below:

sudo apt -y install lsb-release apt-transport-https ca-certificates

Then, use the commands below to add the PPA repository on Debian 11:

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

When your installation is completed, you can proceed to the next step.

Step 4. How To Udate PHP Version on Debian 11?

First, update your local package index with the command below:

sudo apt update

Then, use the command below to install the latest version of PHP:

At the time of writing this guide, the latest version of PHP is PHP 8.1.

sudo apt install php8.1

At this point, you can check your PHP version:

php -v
Udate PHP Version on Debian 11

Note: If you are looking for the most popular PHP extensions, you can use the command below:

sudo apt install php8.1-common php8.1-mysql php8.1-xml php8.1-xmlrpc php8.1-curl php8.1-gd php8.1-imagick php8.1-cli php8.1-dev php8.1-imap php8.1-mbstring php8.1-opcache php8.1-soap php8.1-zip php8.1-intl -y

Conclusion

At this point, you have learned to Upgrade or Update the PHP version on Debian 11 by adding the PPA repository to your server and getting the latest PHP and features for your server. Upgrading PHP on Debian 11 improves security, performance, and compatibility with modern applications while introducing new features and bug fixes. It also ensures extended support and prevents issues from outdated versions.

Hope you enjoy it. Please subscribe to us on Facebook, Instagram, and YouTube.

You may also like these articles:

How To Upgrade PHP Version on Ubuntu 20.04

How To Upgrade PHP Version on Centos 7

Upgrade Bash in Debian

Upgrade Debian Kernel Without Network Connection

FAQs

How do I switch between multiple PHP versions?

If you have multiple PHP versions installed, you can switch with the command below and select the preferred PHP version from the list:
sudo update-alternatives --config php

Will upgrading PHP break my existing applications?

It can if your applications depend on deprecated features. Always test in a staging environment before upgrading.

Can I downgrade PHP if needed?

Yes, remove the current PHP version and install the older one:
sudo apt remove --purge php8.1
sudo apt install php7.4

Share your love

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!