If @eril answer did not help you by disabling old PHP version
sudo a2dismod php8.0
sudo a2enmod php8.1
sudo systemctl restart apache2
use composer -vvv about
to check that composer use correct version of PHP
composer -vvv about 2>&1 | grep "PHP"
if composer about already shows a correct version of PHP,then check to see the real PHP binary path that composer is using by putting PHP_BINARY
inside vendor/composer/platform_check.php
like this:
if (!(PHP_VERSION_ID >= 80100)) {
$issues[] = 'You are running ' . PHP_VERSION . ' located at: ' . PHP_BINARY;
}
in my case, an old version of php-fpm was enabled.
a2disconf php8.0-fpm
a2enconf php8.1-fpm
sudo systemctl restart apache2