Ubuntu -Install PHP
[1] Update Ubuntu
sudo apt-get update
sudo apt-get upgrade
[2] Add Repository for multiple PHP versions
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
[3] Install PHP 8
sudo apt-get install php8.1 php8.1-fpm
[4] Install some common PHP8.1 extensions
sudo apt-get install php8.1-mysql php8.1-mbstring php8.1-xml php8.1-gd php8.1-curl
[5] Check active PHP version
php -v
[6] Install multiple PHP versions
Refer https://techvblogs.com/blog/install-multiple-php-versions-on-ubuntu-22-04