I want to mention a couple things for reference:
- It’s not recommended to set 777 for permissions. The recommendation is 750 for directories, and 640 for files. The owner and group should be the http user (www-data, etc)
- Apparently Nextcloud automatically resets the data directory permissions when you restart the web server, to 770
Nextcloud "data" directory permissions resetting to 770