Good news! PHP 7.1 is being actively supported through 21 Nov 2024. After that point, it's advisable to upgrade to the latest version, since the PHP team will only offer security-related support until 21 Nov 2024, at which point PHP 7.1 will be considered "end-of-life".
Add the Sury PHP repository:
sudo apt update
sudo apt install apt-transport-https lsb-release ca-certificates wget
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
Update package list:
sudo apt update
Install PHP 7.1 and common extensions:
sudo apt install php7.1 php7.1-cli php7.1-common php7.1-json php7.1-opcache php7.1-mysql php7.1-mbstring php7.1-mcrypt php7.1-zip php7.1-fpm
Check PHP version:
php -v
This should display PHP 7.1.x information.
Verify installed modules:
php -m
This will list all installed PHP modules.
Check PHP-FPM status:
sudo systemctl status php7.1-fpm
This should show that PHP-FPM is active and running.