Before switching to PHP 8.2, you have to deactivate the previously activated Apache module. The following commands will deactivate the already activated Apache module and then activate PHP 8.2 Apache module. Then the next commands will set PHP 8.2 as the default version for the command line interface (CLI).
Apache:
-
sudo a2dismod php*
-
sudo a2enmod php8.2
-
sudo systemctl restart apache2
Command line interface:
-
sudo update-alternatives --set php /usr/bin/php8.2
-
sudo update-alternatives --set phar /usr/bin/phar8.2
-
sudo update-alternatives --set phar.phar /usr/bin/phar.phar8.2
-
sudo update-alternatives --set phpize /usr/bin/phpize8.2
-
sudo update-alternatives --set php-config /usr/bin/php-config8.2
Note: The phpize8.2 and php-config8.2 command is available in php8.2-dev package. This is more useful for compiling PHP modules using pecl.
Source: https://tecadmin.net/switch-between-multiple-php-version-on-ubuntu/