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

If you do not have PHPmyAdmin running on your webmin, you can always manage the database under servers->mysql database-> select your db->manage db->select oc_storages in edit db->click view data->select the row with the local:: and edit->set the new value and save.

1 Like

So I’ve been struggling with moving my data directory, as well, in NC v11. My vm test went well, then a trial run on real host to tinker with; and finally, a working, live install…and then I realized I didn’t give enough room for data storage…I have a 2TB external drive.

I have made several attempts, but ran into all the same issues you have with permissions…any idea if this will work in v11?
(This instance is very young: it could be wiped and reinstalled, pointing to the new storage, but I’d like to figure out how to move the data manually…at some point in the future, somebody is going to have to upgrade their storage… might as well find out how).


When moving the data folder to an external drive, make sure you used the correct user to mount the drive…
(Even format as the user depending on the filesystem.)

This should do the same job.

Coming from an otherwise default installation, would that user www-data?

… or just the systems root user?

If default installation means apache webserver, it must be www-data as this it the default web user that is used by nextcloud to write your data. Nextcloud has thanks god no access to the root user ;).

I must have missed something…I log in as root, cp the …/data folder to the new location, but when I run the chown command, it says “operation not permitted”. Suggestions?

… … … …

I have been struggling with this issue all week and finally came across this very useful thread. Thanks to all contributors. However, after going through the various items listed above in robertb’s posting of Sep '16 I still had the mentioned error :

Data directory (/etc/nextclouddata/nextcloud/data/) is invalid. Please check that the data directory contains a file “.ocdata” in its root.

I had learnt in other attempts that the nextcloud.conf has also to be modified by adding the new data directory path as follows (using robertb’s data directory as an example) :

php_admin_value open_basedir “/srv/http/:/dev/urandom:/tmp/:/usr/share/pear/:/usr/share/webapps/nextcloud/:/etc/webapps/:/etc/nextclouddata/nextcloud/data/”

So I tried adding my path and all is working again with a new directory path.

Hope this comment might help those using Nextcloud 11.

Note : I am running on Archlinux so the apache user is “http” and not “www-data”

nextcloud 11.0.2-1
php 7.1.3-1
apache 2.4.25-1
mariadb 10.1.22-1
archlinux 4.10.6-1

Hi, I have the latest version of Nextcloud running on Raspbian. I tried to change the path of the data directory. I moved all /mnt/dietpi_userdata/nextcloud_data files to /mnt/myexternaldrive/nextcloud, then do chown -R www-data:www-data, changed settings in config.php and in oc_storage in the database.

I still get Data directory (/mnt/myexternaldrive/nextcloud) is invalid. Please check that the data directory contains a file “.ocdata” in its root.

I can’t find any nextcloud.conf. What may I do?

Thank you!

Unfortunately I’m a total rookie when it comes to this. I got very lucky with some good advice.

Did you run the following?

chown -R www-data:www-data /mnt/myexternaldrive/nextcoud/data

If I had to guess, it sounds like your path to your data file is specified incorrectly. But again, my experience is minimal.


when re-attaching the external hard drive/usb, make sure you plug it in on the same port.

i had it configured in the fstab and when i plugged it into another port i couldn’t see a thing inside the HDD.

i hope this works for you… :slight_smile:

I have successfully configured nextcloud so that my data-folder is located on a external USB HDD.

Personally, I reinstalled nextcloud because moving the data-folder after installation is not officially supported.

I formatted my HDD as NTFS so the data would be accessible from other OSs and pasted the following last in /etc/fstab (remember to insert correct UUID):
UUID="[INSERT UUID]" /mnt/ekstern ntfs-3g defaults,auto,uid=33,gid=33,umask=077 0 0

Hope this helps.

I posted this on another thread a while back, but thought it could assist you.

Though it may not be supported as others have pointed out in many threads, I have yet to have an issues changing data directorys; I have changed the data directory many times on many different OwnCloud & NextCloud hosts just fine without any issues. These are the steps I take to move the data directory: (This only works if you have no data to move, as if this is a fresh install)

Run the following command in the Linux shell:

o sudo service apache2 stop

o sudo mkdir /media/user/your_hard_drive/nextcloud_data “or whatever you want to call it?” Remember the /media is your mount point or external hard drive.

o sudo chown -R www-data:www-data /media/user/your_hard_drive/nextcloud_data/

o sudo chmod -R 777 /media/user/your_hard_drive/nextcloud_data/

o sudo chown –R www-data:www-data /media

o sudo nano /var/www/html/nextcloud/config/config.php

o Once you are in the config.php you need to change your data directory. Save file and exit.

o Sudo service apache2 start

Hope this helps you out.


I have moved my data folder using the steps described by @wclang and at first sight everything seemed to be fine. However after a restart of my system I received an Internal Server Error right after the login, see “

One step that is missing but mentioned by the previous posts is to update the database table oc_storages. Also you should activate the maintenance mode inside config.php before you apply the changes.

One additional thing I had to do was to delete all the contents from the table oc_filecache. Afterwards I simply restarted Apache, deactivated maintenance mode and when I logged in to nextcloud, everything was working fine again.

For future reference folks, you can also just symlink from /var/www/data (or wherever you set it up initially) to your new location after moving everything. I’m personally a fan of sudo rsync -avP as it preserves all files, permissions, ownership and shows progress as it goes, then deleting the original when I’ve confirmed everything (including hidden files) has been copied over.

That way there’s no need to update the DB and you won’t be told that’s unsupported.


I would add :
6: check the read/write permissions of the new folder (if created and not only moved, as suggested by @robertb )

I should of stated in my post that my process is for fresh builds only without any data in it, if you have data then following “sirea” additional steps will be required. Thanks for pointing that out “sirea” :slight_smile:

note th[quote=“JasonBayton, post:4, topic:3642”]
Make sure no cron jobs are running
Stop apache
Move /data to the new location
Create a symlink from the original location to the new location
Ensure permissions are still correct
Restart apache

Note that you have to configure your webserver to respect that symlink, I believe not all do :smiley:

1 Like