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

#11

exactly
(Post must be at least 20 characters)

#12

I’m at a total loss. I should have a database named nextcloud, but I opened up phpmyadmin and see:

-information_schema
-MySQL
-performance_schema
-phpmyadmin

I’m checking the right server, am I missing something? Sorry for my lack of experience, I may just end up having to reinstall Nextcloud. Hope not, though, it’s working.

#13

@robertb

Hi,

That’s odd. If Nextcloud is working, there has to be a database. Check your config/config.php file for the database type, location, and credentials. It looks something like this,

‘dbtype’ => ‘mysql’,
‘version’ => ‘9.1.0.16’,
‘dbname’ => ‘your database name’,
‘dbhost’ => ‘your database server’,
‘dbport’ => ‘’,
‘dbtableprefix’ => ‘oc_’,
‘dbuser’ => ‘login name’,
‘dbpassword’ => ‘password’,

That should help you locate it.

#14

EDIT* I see the database type is sqlite3 instead of MySQL, I’m guessing this probably has something to do with it?


It’s REALLY odd. I followed these installation instructions:

https://docs.nextcloud.com/server/10/admin_manual/installation/index.html
=> Manual Installation in Linux

/var/www/nextcloud/config/config.php doesn’t even specify a database name. I know it’s working though because I added maintenance mode, switched it to “true”, and the site properly locked me out.

<?php $CONFIG = array ( 'instanceid' => 'zzzzzzz', 'passwordsalt' => 'zzzzzzzzzz', 'secret' => 'zzzzzzzzzzzzzzzzzz', 'trusted_domains' => array ( 0 => 'xxx.xxx.xxx.xxx', 1 => 'share.mydomain.com', ), 'datadirectory' => '/var/www/nextcloud/data/', 'overwrite.cli.url' => 'http://xxx.xxx.xxx.xxx/nextcloud', 'dbtype' => 'sqlite3', 'version' => '9.1.0.16', 'logtimezone' => 'UTC', 'installed' => true, 'mail_smtpmode' => 'smtp', 'mail_from_address' => 'user', 'mail_domain' => 'mydomain.com', 'mail_smtpauthtype' => 'LOGIN', 'mail_smtpauth' => 1, 'mail_smtphost' => 'mail.mydomain.com', 'mail_smtpsecure' => 'tls', 'mail_smtpname' => 'user@mydomain.com', 'mail_smtppassword' => 'mypassword', 'mail_smtpport' => '25', "maintenance" => false, ); I also did a SHOW DATABASES and received exactly the same as what phpmyadmin was showing: MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | phpmyadmin | +--------------------+ 4 rows in set (0.00 sec) But Nextcloud is honestly working just fine. This seems crazy. ANY ideas on what might be happening?
#15

It’s using sqlite instead of Mysql/MariaDB. I think the database will be located in your $data directory and will be a file ending with .db. I’m not entirely sure, as I’ve never configured sqlite before.

#16

I just realized that. Sigh… I think I’ll just try to reinstall

#17

Success!

So with a little digging, I learned that I could convert my database from sqlite3 to MySQL using the following:

https://docs.nextcloud.com/server/10/admin_manual/configuration_database/db_conversion.html

At that point my Nextcloud database was accessible through phpmyadmin. Then I followed grouchysysadmin’s steps above:

0: Back everything up first.
1: Disable access to Nextcloud. (maintenance mode)
2: Move the data folder.
3: Edit the database table oc_storage. Change the local::/path/to/data to local::/new/path/to/data.
4: Edit the config.php datadirectory line to reflect the new path.
5: Turn off maintenance mode.

In my case, I move the data directory to /etc/nextclouddata/nextcoud/data. When trying to load my login page for the first time, I got the following error:

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

Running…

chown -R www-data:www-data /etc/nextclouddata/nextcoud/data

…fixed that error and everything looks to be running perfectly again.

Many thanks to @grouchysysadmin and @nickvergessen for helping me through this.

2 Likes
HowTo: Change / Move data directory after installation
#18

will there be an procedure to do that nativly?

2 Likes
#19

running nextcloud 11.0.1 stable PHP7.0 and MySQL 5.5.53 on webmin/virtualmin raspberry pi3 with debian 8.0

today I moved my data folder to an USB disk ext4

mounted the disk and changed the path accordingly in config.php

‘datadirectory’ => ‘/home/domain/public_html/data’, into ‘datadirectory’ => ‘/mnt/disk/data’,

then using PHPMyAdmin changed the path in OC_STORAGES

(local::/home/domain/public_html/data/ into local::/mnt/disk/data/) just samples

It works like a charm and gave my NextCloud a big boost… not only in space but also in speed.

Please note, in the database the path has a trailing / (forward slash)

1 Like
#20

please guide me how to modify oc_storages as i am unable to find anything as’local’
i am trying t add it by webmin.
Please guide

#21

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
#22

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).

THNX!

#23

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.)

#24

This should do the same job.

#25

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

#26

… or just the systems root user?

#27

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 ;).

#28

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?

#29

… … … …

Arch: how to change data folder location
#30

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”

Running:
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