In this tutorial, we’ll learn how to install PHP (any version) on Debian 12 (bookworm) or any other distro based on Debian 12 such as MX Linux 23, and then we’ll see how to manage multiple versions of PHP. So, let’s open the terminal and get going…
As a rule of thumb, always first update system by entering following command:
sudo apt update && sudo apt upgrade
Next, install required dependencies for adding repos:
sudo apt install software-properties-common ca-certificates lsb-release apt-transport-https
Then add sury repo by entering following command:
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
And then import GPG key:
wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add -
Again, update system by entering:
sudo apt update && sudo apt upgrade
Now, you may install any version of PHP, for example, in order to install PHP 8.1, execute following command:
sudo apt install php8.1
Similarly, you can install the required extensions of a PHP version. For example, in order to get Laravel working you’d need to install following PHP extensions:
sudo apt install php8.1-mbstring php8.1-bcmath php8.1-sqlite3 php8.1-xml php8.1-zip php8.1-gd php8.1-mcrypt php8.1-curl
You may install other versions of PHP too:
sudo apt install php7.4
Finally, to switch between different versions of PHP, enter following command and then select any installed PHP version:
sudo update-alternatives --config php
1 thought on “Install and manage PHP (any version) on Debian 12”