Verry good.
Here you get a Step by Step upgrade procedure of your php:
Step 1
Upgrade your system:
sudo apt-get update && sudo apt-get dist-upgrade
Check if reboot required with this commandline:
[ -f /var/run/reboot-required ] && { echo "Reboot required"; read -p "Press ENTER to reboot or ^C to cancel" dummy; sudo systemctl reboot; exit; } || echo "No reboot required"
Step 2
Install the new php-Packages with this commands:
packages="$(echo $(dpkg -l | awk '/^ii/ {print $2}' | grep -i php7.4 | sed 's/php7\.4/php8.1/g'))"
sudo apt-get install $packages
Step 3
check the configuration files:
You now have two php directories in /etc/php:
/etc/php/7.4
and
/etc/php/8.1
In both directories are two subdirectories that interest us: cli and fpm
Now you have to take over the settings from the 7.4/cli/php.ini and 7.4/fpm/php.ini files into the 8.1 Versions.
If some variables are removed in the new Version, it may be, that those are removed from the new php-version.
Specially this vallues you should look for:
max_execution_time
max_input_time
memory_limit
post_max_size
include_path
sys_temp_dir
upload_tmp_dir
upload_max_filesize
max_file_uploads
default_socket_timeout
opcache.enable
opcache.enable_cli
and if your Nextcloud uses redis:
redis.session.locking_enabled=1
redis.session.lock_retries=-1
redis.session.lock_wait_time=10000
Now you should take a look into the file /etc/php/7.4/fpm/pool.d/www.conf
and take over this settings into the new (8.1) Version:
pm.max_children
pm.start_servers
pm.min_spare_servers
pm.max_spare_servers
pm.max_requests
Step 4
Now deaktivate the old php7.4-fpm and activate the new php8.1-fpm with this commands:
sudo a2disconf php7.4-fpm
sudo a2enconf php8.1-fpm
sudo systemctl reload apache2
Step 5
Check if your Nextcloud is running as expected.
Step 6
Remove the old php:
sudo apt-get remove --purge php7.4*
Step 7
Do the Nextcloud Server update:
sudo -u www-data php -f /var/www/nextcloud/occ app:update --all
sudo -u www-data php -f /var/www/nextcloud/updater/updater.phar
Calmly do everything step by step!
Much luck