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 system package list:
sudo apt update
Add the PHP repository:
sudo add-apt-repository ppa:ondrej/php
Install PHP 8.1:
sudo apt install php8.1
Install common PHP extensions:
sudo apt install php8.1-common php8.1-mysql php8.1-xml php8.1-xmlrpc php8.1-curl php8.1-gd php8.1-imagick php8.1-cli php8.1-dev php8.1-imap php8.1-mbstring php8.1-opcache php8.1-soap php8.1-zip php8.1-intl
Check the PHP version:
php -v
The output should show PHP 8.1.x
Verify installed PHP modules:
php -m
This will list all installed PHP modules
Create a PHP info file:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
Access the PHP info page in a web browser:
http://your_server_ip/info.php
This page will display detailed information about your PHP installation