Is there a safe and reliable way to move data directory out of web root?

Be aware, moving the data dir after installation is not supported and may cause issues.

Edit 2017 (as this is a popular topic):

If you have a fresh install, consider reinstalling with your preferred directory location.

Unofficially moving the data directory can be done as follows:

  1. Make sure no cron jobs are running
  2. Stop apache
  3. Move /data to the new location
  4. Change the config.php entry
  5. Edit the database: In oc_storages change the path on the local::/old-data-dir/ entry
  6. Ensure permissions are still correct
  7. Restart apache

However this is not supported and you risk breaking your database. It’d be better if instead you:

  1. Make sure no cron jobs are running
  2. Stop apache
  3. Move /data to the new location
  4. Create a symlink from the original location to the new location
  5. Ensure permissions are still correct
  6. Restart apache

(Note, you may need to configure your webserver to support symlinks)

Which is supported by Nextcloud.

7 Likes