8.2 is the latest major version of PHP, which was released on the 8th of December 2022. You can read up on new features and changes here.
To install PHP 8.2 on Ubuntu 22.04
Start by updating the package list:
sudo apt update
Add the independent software sources:
sudo apt install software-properties-common
Now add the repository which contains the up-to-date PHP release versions:
sudo add-apt-repository ppa:ondrej/php
Press enter when prompted.
For apache2:
sudo apt install php8.2 libapache2-mod-php8.2
Or for Nginx:
sudo apt install php8.2 php8.2-fpm
Press y to confirm and install.
Next you can install some PHP extensions:
sudo apt install php8.2-{bz2,curl,mysql,xml}
Restart apache:
sudo systemctl restart apache2
Or restart Nginx:
sudo systemctl restart nginx
If you already had a lower PHP version installed you can switch to 8.2 with:
Apache2:
sudo a2dismod php8.1
sudo a2enmod php8.2
Nginx:
sudo a2disconf php8.1-fpm
sudo a2enconf php8.2-fpm
You will need to restart the web server again (apche2 or Nginx).
Confirm your PHP version with:
php -v