Good news! PHP 8.2 is being actively supported through 31 Dec 2024. After that point, it's advisable to upgrade to the latest version, since the PHP team will only offer security-related support until 31 Dec 2026, at which point PHP 8.2 will be considered "end-of-life".
sudo apt update
sudo add-apt-repository ppa:ondrej/php
sudo apt install php8.2
sudo apt install php8.2-common php8.2-mysql php8.2-xml php8.2-curl php8.2-gd php8.2-imagick php8.2-cli php8.2-dev php8.2-imap php8.2-mbstring php8.2-opcache php8.2-soap php8.2-zip
php -v
You should see output similar to:
PHP 8.2.x (cli) (built: ...) (...)
php -m
php --ini