Hello, in this article, I will explain how we can work with different PHP versions under Pardus 21 (including Debian Bullseye) according to my own experience.

It is possible to get out of this by using PPA under Ubuntu and DPA under Debian.

First of all, we define our warehouse.

sudo apt install apt-transport-https lsb-release ca-certificates sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

Then we run the following command

sudo sh -c 'echo "deb https://packages.sury.org/php/ bullseye main" > /etc/apt/sources.list.d/php.list'

We are updating our repositories.

sudo apt update

After running the commands in order, we move on to the package installation. We install the base packages.

sudo apt install curl apache2

PHP 8.2 If I'm going to use the version, I install the following packages. You can customize it according to your needs.

sudo apt install php-common libapache2-mod-php8.2 php8.2-cli php8.2-common php8.2-opcache php8.2-readline php8.2-curl php8.2-gd php8.2-imagick php8.2. 8.2-intl php8.2-mbstring php8.2-mysql php8.2-xdebug phpXNUMX-xml

PHP 8.1 If I'm going to use the version, I install the following packages.

sudo apt install php-common libapache2-mod-php8.1 php8.1-cli php8.1-common php8.1-opcache php8.1-readline php8.1-curl php8.1-gd php8.1-imagick php8.1. 8.1-intl php8.1-mbstring php8.1-mysql php8.1-xdebug phpXNUMX-xml

PHP 8.0 If I'm going to use the version, I install the following packages.

sudo apt install php-common libapache2-mod-php8.0 php8.0-cli php8.0-common php8.0-opcache php8.0-readline php8.0-curl php8.0-gd php8.0-imagick php8.0. 8.0-intl php8.0-mbstring php8.0-mysql php8.0-xdebug phpXNUMX-xml

PHP 7.4 If I'm going to use the version, I install the following packages.

sudo apt install php-common libapache2-mod-php7.4 php7.4-cli php7.4-common php7.4-opcache php7.4-readline php7.4-curl php7.4-gd php7.4-imagick php7.4. 7.4-intl php7.4-mbstring php7.4-mysql php7.4-xdebug phpXNUMX-xml

You can install previous versions under the same logic.

When the packages are installed, some features such as ssl and rewrite need to be enabled, I enable them.

sudo a2enmod ssl rewrite suexec include

Then we open our ini file with the editor (I use gedit) to activate the error display.

PHP 8.2 The path for our ini file is as follows:

sudo gedit /etc/php/8.2/apache2/php.ini

PHP 8.1 For this, the path of our ini file is as follows:

sudo gedit /etc/php/8.1/apache2/php.ini

PHP 8.0 The path for our ini file is as follows:

sudo gedit /etc/php/8.0/apache2/php.ini

PHP 7.4 The path for our ini file is as follows:

sudo gedit /etc/php/7.4/apache2/php.ini

After editing the ini file according to my needs, we restart apache for the settings to take effect.

sudo service apache2 restart

http://localhost/ adresine tıkladığımızda dosyalarımız görünüyorsa apache kurulmuş demektir.

Now we can create a test file and look at phpinfo().

Well, after installing the above PHP versions, how do we switch between them?

You can set the PHP version with the following command.

sudo update-alternatives --config php

Of course, it will be necessary to restart the server at the end of the whole process.

sudo service apache2 restart

You can also use the command line to see the PHP version from the terminal.

php-v

references: