Upgrading from a pi 3 running nextcloudpi to a pi 5

Dear Nextcloud community,
I recently purchased a raspberry pi 5 with 8GB of RAM to replace my currently used pi 3b+. On the pi 3b+, I’m running a nextcloudpi-image with Nextcloud Hub II (23.0.2). Sadly, I can’t copy this installation to my pi 5 because it can’t run on PHP 8.2, and I can’t update my pi because the buster upgrade always fails

0 aktualisiert, 0 neu installiert, 1 zu entfernen und 12 nicht aktualisiert.
Nach dieser Operation werden 102 kB Plattenplatz freigegeben.
(Lese Datenbank ... 59679 Dateien und Verzeichnisse sind derzeit installiert.)
Entfernen von php7.3-gmp (7.3.33-14+0~20230902.114+debian10~1.gbp764b27) ...
(Lese Datenbank ... 59670 Dateien und Verzeichnisse sind derzeit installiert.)
Löschen der Konfigurationsdateien von php7.3-gmp (7.3.33-14+0~20230902.114+debian10~1.gbp764b27) ...
Paketlisten werden gelesen... Fertig
Abhängigkeitsbaum wird aufgebaut.
Statusinformationen werden eingelesen.... Fertig
Paket »php7.3-imagick« ist nicht installiert, wird also auch nicht entfernt.
0 aktualisiert, 0 neu installiert, 0 zu entfernen und 12 nicht aktualisiert.
sed: /etc/systemd/system/dhcpcd.service.d/wait.conf kann nicht gelesen werden: Datei oder Verzeichnis nicht gefunden
Something went wrong. Fix it and try again

I also cant install a nextcloudpi-image on the pi 5 because that also fails and I don’t know how to install the PHP version that works next to the nextcloud version on the pi 5.
Can someone help?
Thanks for your answers.

You can use the Sury/PPA packages to install different PHP versions in parallel across Debian and Ubuntu based distros and across different versions: DEB.SURY.ORG

If you get stuck, you can search here for numerous posts on using the Sury packages.

Another approach, which you might consider, is to switch one of the at least three Docker-based installers for Nextcloud. That bypasses messing with PHP versions entirely and will make future upgrades and migrations easier.

Thank you for your reply! For anyone wondering how I managed to do the upgrade in the end, I didn’t had to switch to docker, I just had to copy the nextcloud/config, the nextcloud/data and the nextcloud/themes folder to a new installation of the newest version of nextcloud and the updater will do the rest. You might have to update some apps and fix some database errors but the NC updater will do most work for you.