Kind of a random game over the years to optimize PHP 7.x and 8.x for Nextcloud and there are a variety of disclaimers on what you might think about doing for your specific instance, etc. based on server capacity and size of files, apache or nginx, and all that stuff. Not to mention the ambiguity around PHP, PHP-FPM, and whether you are using caching or not and all those separate possible config settings that can cause hours of fun to mess with.
Anyway, here is what I am currently running now after finally stepping away from PHP 7.4.x and into PHP 8.1 w/PHP-FPM on Debian. Again, YMMV, but just putting this out there for others as the search for something definite is a pretty tough effort elsewhere.
Your paths may vary and there are numerous connected/overlapping php.ini files so that is a challenge as well because some areas of php are broken-out into sub directories by version, etc. Check your php.info to try and get a handle on where everything is for you.
Here are some files and settings of note I have been messing with and am somewhat happy with now on Nextcloud 25.03 and PHP 8.1.x as of January 2023. Running on a 32gb RAM Intel i7 hardware setup. Again, after many, many, many, years on Nextcloud and running PHP in a variety of apps, this is all pretty much guessing at this point. No real opinion but hope this might help you in some way as you explore your own personal journey with all of this.
memory_limit = 4G post_max_size = 0 upload_max_filesize = 50G [opcache] opcache.enable=1 opcache.enable_cli=1 opcache.memory_consumption=1024 opcache.interned_strings_buffer=64 opcache.max_accelerated_files=5000000 opcache.max_wasted_percentage=15 opcache.validate_timestamps=0 opcache.revalidate_freq=60 opcache.save_comments=1 opcache.optimization_level=0x7FFFBFFF opcache.max_file_size=0
pm = dynamic pm.max_children = 200 pm.start_servers = 20 pm.min_spare_servers = 12 pm.max_spare_servers = 30