docs / https / how-to-change-move-nextcloud-data-directory-after-installation
How To: Change / Move Nextcloud data directory after installation
The solution is far simpler and less risky in data corruption concerns, but it does NOT fulfil the security recommendations.
So if you just need to move the data directory for storage reasons, not for security reasons, just create a symbolic link from old to new data directory location. For that you only need to be sure, that symbolic links are correctly handled by your webserver. Nginx should handle symlinks correctly by default, for apache the related option needs to be set in your Nextcloud vhost, as already given by the admin manual example: Installation on Linux — Nextcloud latest Administration Manual latest documentation
<Directory /path/to/nextcloud/>
Options +FollowSymlinks
…
</Directory>If so, then do:
sudo -u www-data php /path/to/nextcloud/occ maintenance:mode –on
mkdir -p /new/path/to/data
cp -a /path/to/data/. /new/path/to/data
mv /path/to/data /path/to/dataBackup
ln -s /new/path/to/data /path/to/data
chown -h www-data:www-data /path/to/data # To set symlink ownership
chown -R www-data:www-data /new/path/to/data # To set actual data dir ownership
sudo -u www-data php /path/to/nextcloud/occ maintenance:mode –offAgain, if everything works fine, you could remove /path/to/dataBackup or just keep it as regular backup.
Note: If you want to adjust permissions of your new data folder, you need to chmod -R XYZ /new/path/to/data, as chmod does not follow symlinks.