I prefer to have the nextcloud data directory not in the webroot of the nextcloud server.
→ Nextcloud webroot and data directory - best practices on Ubuntu 18.04 LTS
try the following steps:
stop all nginx, database redis tasks
systemctl stop nginx …
- make a directory somewhere outside the path /var/www/nextcloud → maybe /media/nextcloud/my-data-dir
- change ownership of this new data dir → sudo chown -R www-data:www-data /media/nextcloud/my-data-dir
- copy all (!) hidden and no-hidden files of your actual data dir /var/www/nextcloud/ncdata to /media/nextcloud/my-data-dir
- zip your old ncdata dir as backup if something needs to be restored later (!)
- move the zip file away from /var/www/nextcloud and delete your ncdata folder
- edit your /var/www/nextcloud/config/config.php datadirectory path to your new path /media/nextcloud/my-data-dir
- repeat the command sudo chown -R www-data:www-data /media/nextcloud/my-data-dir to be sure that all files and folders are owned by your webserver user and also check that www-data user has read/write access to all files and folders (!)
- start the nginx, database, etc.
- run command sudo -u www-data php /var/www/nextcloud/occ integrity:check-core
Login to your WebUI and enter the Admin section and re-check if everything works fine.