PHP 8.1 reached end of active support on 25 Nov 2023. As of today, PHP 8.1 is only receiving security related updates through 31 Dec 2025, at which point it will be considered end-of-life and receive no further updates. It's strongly recommended to upgrade to the latest version of PHP before then.
Update the package list:
sudo apt update
Install required packages:
sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2
Add the Sury PHP repository:
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/sury-php.list
Import the repository GPG key:
wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add -
Update the package list again:
sudo apt update
Install PHP 8.1:
sudo apt install -y php8.1
Check the installed PHP version:
php -v
Verify PHP configuration:
php -i
Create a test PHP file:
echo '<?php phpinfo(); ?>' | sudo tee /var/www/html/phpinfo.php
Access the phpinfo page in your web browser:
http://your_server_ip/phpinfo.php