Installing PHP 7.4 (By default, Debian 12 install php 8.2 but we are using here php 7.4)
apt-get -y install lsb-release ca-certificates curl
curl -sSLo /etc/apt/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
sh -c 'echo "deb [signed-by=/etc/apt/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
apt-get update
Edit nano /etc/apt/preferences.d/stable
This is to tell debian to use default Debian repo to install packages.
Package: *
Pin: release o=Debian
Pin-Priority: 900
Edit nano /etc/apt/preferences.d/php
This is to tell debian to use sury as repo for php 7.4 and lower and for 8.2, use default repo.
Package: php*
Pin: origin "packages.sury.org"
Pin-Priority: 900
Package: libapache2-mod-php*
Pin: origin "packages.sury.org"
Pin-Priority: 900
Install php
apt-get update
apt install php7.4
apt install php7.4-zip php7.4-curl php7.4-json php7.4-xml php7.4-posix php7.4-mysqlnd php7.4-gd php7.4-curl php7.4-mbstring php7.4-pdo php7.4-pgsql
apt install libapache2-mod-php7.4
Restarting apache2
systemctl restart apache2
Enabling mod-rewrite
a2enmod php7.4