1. Add PPA for PHP 8.2
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
2. Install PHP 8.2
sudo apt install php8.2
3. Install PHP 8 Packages
sudo apt install php8.2 php-common php8.2-apcu php8.2-cli php8.2-common php8.2-curl php8.2-fpm php8.2-mysql php8.2-opcache php8.2-readline
4. Enable PHP 8.2
sudo a2dismod php8.0
sudo a2enmod php8.2
sudo service apache2 restart
Now to check php version. Use Following Command.
php -v
If it’s still show old php version then you can run bellow command and choose new php version from there list. so run bellow command:
sudo update-alternatives --config php
Then it will works.