Requirements:
A PC running Debian 9 (Stretch)
An internet connection
Root access using sudo or su
apt-transport-https
lsb-release
ca-certificates


Step 1:

Install the latest version of apt-transport-https, lsb-release, and ca-certificates using
$~: sudo apt install apt-transport-https lsb-release ca-certifiactes


Step 2:

Fetch the repository key using
$~: sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg


Step 3:

Option 1: using Su:

Add packages.sury.org to your sources list using
#: echo "deb https://packages.sury.org/php/ stretch main" > /etc/apt/sources.list.d/php.list

Option 2: using Sudo:

Add packages.sury.org to your sources list by entering the following command
$~: sudo apt edit-sources
then add the following line to the end of the file that opens
deb https://packages.sury.org/php/ stretch main


Step 4:

Update your packages list to include the new packages using
$~: sudo apt update