It’s in their docs. https://docs.nextcloud.com/server/latest/admin_manual/installation/index.html
Follow the pages one by one, (ie install php modules etc, edit settings, install apache2, edit settings, etc etc). Follow the recommendations (eg. PHP8.2, don’t try to use bleeding edge).
You’ll be running in no time, and have a properly updatable system using apt, and the nextcloud ./occ command.
I would recommend using Debian 12 over Ubuntu variants. There are other guides, like this: https://www.digitalocean.com/community/tutorial-collections/how-to-install-and-configure-nextcloud But you may have to “convert” some of the Ubuntu specific stuff to Debian, but actually there is probably no difference (php module naming convention maybe? Is that still a problem today?)
31 branches? uh… okay.