I’ve been dealing with the same issue with the VM version and only recently managed to successfully update to PHP 8.1, thanks to the pointers in this thread and https://help.nextcloud.com/t/cannot-upgrade-to-nc-26-due-to-php-7-4/158523
Especially the detailed instructions of ernolf helped a lot.
No guarantees, but hopefully these steps will also work for you, see https://help.nextcloud.com/t/cannot-upgrade-to-nc-26-due-to-php-7-4/158523/21?u=dhrto