On Ubuntu several PHP releases can be installed side by side, but Apache loads only one mod_php module at a time, and the command line php binary is selected separately through update-alternatives. These are the steps we use to move a web server from one PHP release to the next. The example switches from 7.1 to 7.2 and works the same way for 8.x.
1. See what is installed
apt list --installed | grep -i php
To remove an old release completely, here PHP 5:
apt-get purge php5*
2. Switch the Apache module
a2dismod php7.1
a2enmod php7.2
service apache2 restart
3. Switch the command line binaries
update-alternatives --set php /usr/bin/php7.2
update-alternatives --set phar /usr/bin/phar7.2
update-alternatives --set phar.phar /usr/bin/phar.phar7.2
update-alternatives --set phpize /usr/bin/phpize7.2
update-alternatives --set php-config /usr/bin/php-config7.2
The last two are only needed when PECL extensions are compiled on the server.
4. Check the loaded Apache modules
apachectl -M
The list must contain php7_module (or php_module for PHP 8) and no module of the old release. The same list is visible in Joomla under System Information.
5. php.ini values for Joomla
Each release has its own php.ini, so the settings have to be applied again in /etc/php/7.2/apache2/php.ini. These values clear the warnings under Joomla > Extensions > Warnings:
upload_max_filesize = 64M
post_max_size = 64M
sys_temp_dir = "/tmp"
upload_tmp_dir = /tmp
6. Remember the two php.ini files
The command line PHP may read a different configuration from the one loaded by Apache:
php -i | grep -i php.ini
Configuration File (php.ini) Path => /etc/php/7.2/cli
Loaded Configuration File => /etc/php/7.2/cli/php.ini
Reference: PHP supported versions. Related: web hosting by GOLINE.