How To Upgrade PHP Version on Debian 11

In this guide, we want to teach you How To Upgrade or Update 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 this guide to see how to do it.

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:

Output
PHP 7.4.30 (cli) (built: Jul  7 2022 15:51:43) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.30, Copyright (c), by Zend Technologies

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 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:

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 Upgrade PHP 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
Output
PHP 8.1.12 (cli) (built: Oct 28 2022 18:32:13) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.12, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.12, Copyright (c), by Zend Technologies

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.

Hope you enjoy it. You may be like these articles:

How To Upgrade PHP Version on Ubuntu 20.04

How To Upgrade PHP Version on Centos 7

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!