Installing PHP can be either from Debian default repository which is stable but is not upto date or from the sury.org repositoy which provide the latest packages compatiable with debian and Ubuntu.
This article shows the steps to create an APT source list file that allows you to the latest version of PHP repository for Debian and Ubuntutu.
What is SURY?
SURY repository contains many packages, however, PHP is what it is famous for. more details on their website
Steps to Create a repository for PHP
The following step will do the following
First, install a few tools required
Next, add the repository key to Trusted keys.
Then, Create the repository source list.
sudo apt-get install curl apt-transport-https
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" > /etc/apt/sources.list.d/php.list
Install PHP packages
to facilitate the installation process. I create a variable pv to hold the version you want it could be 7.0, 7.1, 7.2,7.3, 7.4 or 8.0
pv="7.0"
#Core liberrary
apt-get install -y php$pv php$pv-common php$pv-zip php$pv-fpm php$pv-curl
#structure support XML, JSON, Yaml
apt-get install -y php$pv-yaml php$pv-json php$pv-xml php$pv-xmlrpc
apt-get install -y php$pv-cli php$pv-gd php$pv-intl php$pv-tidy php$pv-xsl
#Encryption and ldap authentication
apt-get install -y php$pv-ldap php$pv-mcrypt
#performance enhancement
apt-get install -y php$pv-mbstring php$pv-bcmath php$pv-readline
#caching
apt-get install -y php$pv-memcache php$pv-memcached
# database modules
apt-get install -y php$pv-mysql php$pv-redis
Finally, Check if the FPM service is active by typing.
systemctl status php$pv-fpm