In this guide, we want to teach you How To Upgrade or Update PHP Version on Debian 11.
PHP is an open-source server-side scripting language that many devs use for web development. It is also a general-purpose language that you can use to make lots of projects, including Graphical User Interfaces (GUIs).
Steps 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.
Check Current Debian PHP Version
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
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
Add PPA repository on Debian 11
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.
Update Debian 11 PHP Version
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:
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
The command below includes some of the most popular PHP extensions:
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.
Hope you enjoy it.
You may be like these articles: