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 PHP 8.1 and common extensions:
sudo apt install php8.1 php8.1-cli php8.1-common php8.1-curl php8.1-mbstring php8.1-mysql php8.1-xml
Optionally, install additional PHP extensions as needed:
sudo apt install php8.1-gd php8.1-zip php8.1-bcmath
Check the installed PHP version:
php -v
You should see output indicating PHP 8.1.x is installed.
Verify PHP CLI is working:
php -r "echo 'PHP is working!';"
This should output: PHP is working!
Check installed PHP modules:
php -m
This will list all installed PHP modules.