Nextcloud does not allow moving the data folder?

Greetings,
I have an Ubuntu File Server running Ubuntu Server v22.04. The OS is installed on a 250GB boot SSD drive and I have an 8TB secondary SSD drive. After some fishing around through a bunch of folders I learned my latest Hub3 v25.0.4 Nextcloud app got installed at the ROOT level at the path shown below:

/var/www/nextcloud

Is this the correct install location? Shouldn’t the correct install location be somewhere at the HOME/user account directory level?

Here is the problem. When I try to open the DATA folder shown in the screen capture below a message appears saying I am not permitted to open this folder. This makes no sense to me because I have ROOT ADMIN level privileges.

In short, my goal is to move the Nextcloud data folder to my secondary 8TB SSD drive so I can save all my Music, Contacts, Bookmarks, Calendar, etc. to the 8TB SSD drive. I do not want to be saving any of my personal data to the 250GB Boot drive.

Can anybody in this community please point me to the best tutorial online that will show me how to reconfigure my NextCloud installation so it saves all my personal data to my secondary 8TB SSD drive?

Or better yet can someone in this forum please post all the necessary Ubuntu Server Terminal commands needed to move Nextcloud’s data folder to a new SSD drive location? I have not been able to find anything online that shows all of the needed Linux commands in a sequential order.

I will welcome any help because I have hit a brick wall with this problem. I wish it was possible to perform this task within the Nextcloud environment but it seems that is not possible. It looks like it can only be done using Linux terminal commands. Thank you for your time.

Nextcloud Version: Hub3 v25.0.4 manually installed (This is a Non-Snap install. )
MariaDB manually installed
Apache manually Installed
PHP manually installed

No, it should not. This is because the web server user (www-data on Ubuntu) must retain exclusive ownership of all files in its data folder.

The data folder itself can be anywhere you like. You can find some tutorials on changing it, but the high level overview is that you will shut down Nextcloud, move the data folder (being careful to maintain file permissions and timestamps), edit the Nextcloud config with the new path, and start it back up. It should be able to continue on like nothing has changed.

hello you should not mix server with client and system user with normal user. And aside the linux users are separately from the cloud users unless your using ldap which you do not.

reading your post I assume you have no knlowledge of what your doing. ( no offence everyone needs to start somewhere ) .

yet imo you have choosen the best/easiest maintainable installation.

looking at your screenshot it looks like everything should be working as it is.

yes nextcloud will be installed in /var/www/nextcloud this is correct and fyi is not the root folder which would be /nextcloud

you should familiarize yourself with the linux filestructure / /home /usr /var and how file permisions work.

nextcloud is only a website it does nothing for you system related. You will have to tell the system what to do with nextcloud.

your current data location is /var/www/nextcloud/data it is owned by a system-user. this user (www-data) has been disabled to login as it is not a real user. it is only used to run specific applications in this case apache webserver.

a normal user that can login should not be able to edit files in /var/www as this location is set for the webserver thus you would need root access as a user to edit here.

to change you data location you only need to prepare the new location with the correct permissons and set it in your config.

first you must find where the ssd is mounted.
you can list your hdd/ssd with

fdisk -l

you will see your disk and it’s device name ex. /dev/sda

now use

df -h

this will show a list of your filesystem and where they are mounted.

lets say /dev/sda1 is mounted at /mnt/8TBdata and you want the whole drive to be your data folder for nextcloud. then this folder /mnt/8TBdata needs to be writable by the www-data user. there are two things that set permissions the user and the file/folder.

setting the user we use

sudo chown www-data:www-data /mnt/8TBdata

setting the file we use

sudo chmod 750 /mnt/8TBdata

once set ls -l /media should return

drwxr-x— 2 www-data www-data 4096 mar 20 2023 8TBdata

you can now set maintenance on.

sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --on

copy the existing data to it’s new location

sudo -u www-data cp -r /var/www/nextcloud/data/. /mnt/8TBdata/

set your new data location.

sudo -u www-data php /var/www/nextcloud/occ config:system:set datadirectory --value=/mnt/8TBdata

disable maintenance

sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --off

so in short

set correct permissions on new disk.
copy nextcloud user data.
set new location in config.php.

there are many posts about the data directory that have usefull information.

there is no one tutorial that fits all needs.

Thank you KarlF12 and Vincent for your help. Vincent I really appreciate how you have sequentially lined up the Linux terminal commands in the order one needs to follow for somebody with my type of hardware and software configuration. I spent my last weekend free time configuring my 8TB SSD so it automatically mounts upon OS bootup by adding the secondary 8TB SSD drive information shown below to the Fstab file:

  • 8TB drive UUID code
  • /mnt/8TBdata (I read “mnt” is better for internal SSD & “media” is great for external USB mounted drives. So I opted for “mnt”).
  • /dev/sda

I have tested my 8TB drive by saving files to it and it works great. And I have confirmed it does indeed automatically mounts.

Vincent, what I find perplexing is how you make no mention of any MariaDB configuration changes. My understanding is MariaDB is the SQL database app that Nextcloud uses to store data in. So I was thinking it was going to be necessary to sign into MariaDB and in some way setup a parameter instructing MariaDB to save all of the data to this new path: /mnt/8TBdata/Nextcloud_data. In short, may you please clarify why no MariaDB involvement is necessary when changing Nextcloud’s save to location to a secondary drive?

I hope by next weekend I can have all of the necessary jigsaw puzzle pieces collected so I could put this puzzle together and all figured out because this has turned out to be the most challenging aspect of setting up Nextcloud. It would be awesome if somebody could create a YouTube video on this specific topic.

Once again thank you to all for your help with this matter.

Two things:

1:
The Database layer is not holding the data files. It holds indices, settings, users, user settings and much other things. But never user data files.

2:
To move the database itself to other location is a database exclusive operation. There are several articles out there of how to do this for MariaDB, but you seems to have PLENTY of space for the database on your 1TB drive. Is there a specific reason you would like to move the database as well?

I think in Nextcloud database, it use the datadirectory relative path of files only.
So move / relocate the datadirectory and tell Nextcloud where it is, it should be fine.
Am I right?

1 Like

Yup! Correct.

truely there is not better. one is not faster yhen the other there basicly identical. As a long time unix user my understanding was /mnt has been there from the beginning /media is it’s new replacement.

imho /mnt is indeed clearer for internal disks. /media for external usb. I don’t know if /mnt will disappear in the future (by default) on can always create it.

once nextcloud is setup you have created a sql user for it. nextcloud will handle all database connections. once you created the database user you basicly never have to connect to the database yourself.

nextcloud configuration is stored /var/www/nextcloud/config/config.php

Kerasit and a3linux, just to clarify, I have no plans to move the MariaDB app (unless it is necessary). I prefer it just stay put where it is which is on my 250GB boot drive. Nevertheless, it is great to now know the Maria database layer is not holding the actual data files. This means I do not have to worry about my 250GB boot drive getting filled to capacity once I migrate 5,000 music tracks to my NextCloud data folder relocated to my 8TB secondary drive since the MariaDB on my boot drive is not holding the actual user files.

Lastly, not much luck on finding a great YouTube video on the subject of moving the Nextcloud Data folder to a different hard drive location. The only one I was able to find relates to adding a new hard drive to NextCloud using an app called “External Storage”. The link to the YouTube video is below:

https://www.youtube.com/watch?v=D8eDnlGDUk4

If this Nextcloud “External Storage” app can be used to add a new external storage hard drive to Nextcloud, is it a big leap to expect this app to also have the ability to move the Nextcloud data folder to a new hard drive location? It would be great if it does because I would prefer to bypass using Linux terminal commands if possible and instead perform this NextCloud data folder reconfiguration operation within the Nextcloud environment with such an app. Any advice welcome.

1 Like

I never used External Storage in Nextcloud before even though I knew it is adding some external storage volume or space to Nextcloud outside the standard datadir.
I do not know much about External Storage to replace or reconfig as primary datadir.

For my experience is,
I lost my system disk(SSD hold OS and database) and I restore the database by database backup SQL file and Nextcloud occ files:scan with the same datadir mount to my Nextcloud re-installation instance. I knew that, I do not lost anything with my old system disk gone.

Just for your reference.

this is very complex and would require more (occ) terminal commands. aside that nextcloud is run by the system user www-data, this user (by default) has no access to your system outside /var/www/ so It could not setup access to /mnt/ you must first setup correct permissions with a root account.

the same counts for external storage but external storage also has login option. ( I’m not familiar with the login. I don’t think you can login as a linux user to for ex. capture there /home/username )

external storage is usefull to share with groups. for example. you could store all your music in a folder (or the complete 8TBssd or a folder there) and share it with a certain group.

call your external storage music and share it with the group music-users.
everyone in this group will get a folder music in there root directory.

I will break it down to you:

This is the minimum that SHOULD be enough:
mkdir /mnt/newdrive-name/whatever/data
chown www-data:www-data /mnt/newdrive-name/whatever/data
php /var/www/nextcloud/occ maintenance:mode --on
mv /var/www/nextcloud/data/* /mnt/newdrive-name/whatever/data
php /var/www/nextcloud/occ config:system:set datadirectory --value=/mnt/newdrive-name/whatever/data

This is what I recommend to run also, but SHOULD not be needed:
php /var/www/nextcloud/occ files:cleanup
php /var/www/nextcloud/occ files:scan --all
php /var/www/nextcloud/occ maintenance:data-fingerprint
php /var/www/nextcloud/occ maintenance:repair

End all of it with ending maintenance mode.
php /var/www/nextcloud/occ maintenance:mode --off

For good sake but not because it SHOULD be needed:
systemctl restart apache2.service (or NGINX depending on what you use)
systemctl restart php8.1-fpm,service (IF php FPM is what you use)

Vincent,
You say at the end to “set new location in config.php.” The Youtube video below I found shows editing the “config.php” file using nano with this command:
nano /var/www/nextcloud/config/config.php

May you please clarify how your commands bypass the need to use Nano for the purpose of editing the “config.php” file? My newbie command writing skills do not allow me to see how you eliminate the need for Nano. Thank you for your time.

https://www.youtube.com/watch?v=VHF89bZR0bg

The command:

php /var/www/nextcloud/occ config:system:set datadirectory --value=/mnt/newdrive-name/whatever/data

sets the configuration file. This removes the need to edit directly with nano. See

https://docs.nextcloud.com/server/18/admin_manual/configuration_server/occ_command.html#config-commands-label

for the full details.

1 Like

my choice to use the occ command to change the config.php and not nano or vi is because

  1. nano/vi needs explaination how to use
  2. using occ prevents typing errors.
    which results in other errors.

the how and what is like MartinRushton said above

Vincent,
Thank you for your post. Moreover, you say “Once set ls -l /mnt should return”
drwxr-x--- 2 www-data www-data 4096 mar 20 2023 8TBdata

What I get is shown below and as you can see I get a “4” (Read Only Permission) and not the “2” (Write Access Only Permission) you say I should see.
drwxr-x--- 4 www-data www-data 4096 mar 20 2023 8TBdata

Before running the ls -l /mnt command I ran the two commands shown below from this location root@mysrvr:/mnt/8TBdata#

First Command I have executed :
sudo chown www-data:www-data /mnt/8TBdata

Second Command I have executed:
sudo chmod 750 /mnt/8TBdata

Third Command I have executed:
root@mysrvr:/mnt/8TBdata# ls -l /mnt
And I get:
drwxr-x--- 4 www-data www-data 4096 mar 20 2023 8TBdata

Shouldn’t using the 750 code generate a “drwxr-x— 2” result for me as well?

Also to clarify should all of the commands you have posted require I run them from my root@mysrvr:~# user account? Or from my regular user account named "me@mysrvr:~$ ". I ask because I am wondering what account is the preferred one to use and whether that makes a difference.

Lastly, I have not yet run the Fourth command shown below because I would first like to know the “drwxr-x— 4” versus “drwxr-x— 2” is an error I first need to fix.

Fourth Command (Not Yet Executed):
sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --on

Any advice you or anyone in this forum may have will be tremendously appreciated.

well for the number 2 you get where I wrote 4 is is not related to the permissions. only the first letters drwx.

the number after represents the amount of subfolders in that directory.

when it is a file it represents the number of hardlinks.

this will explain it better The UNIX School: Link count: File vs Directory.

so your 2 is okay and will increase to 3 when you create a subfolder.

for the user.

this is imo the most important. you should never execute anything as root. you should use a user account and execute root commands with the correct permissions using sudo

this elevates the permissions of the user to root or to anyother user.

as sudo -u www-data executes the command as user www-data.

so the preferd user is your user account me@mysrvr.

more over sudo What is the sudo (su 'do') command-line utility? – TechTarget Definition.

kudos for your follow up questions and not blindly copy and execute.

Bit OT, but not much.

When I started in UNIX many years ago it was stressed that the hash prompt (ie root) meant “any mistake makes a complete hash of the system” whereas the dollar prompt (ie a normal user) meant “you’ll save yourself dollars”. A bit corny, but it emphasises the issue: if you act as root the system will do just as you ask, however stupid. This was doubly so when running a multi-user machine!

1 Like

Vincent,
Thank you for your post.

I ran the command below from my me@mysrvr:~$ normal account location:

sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --on

I got what seems to be an error. Please take a look at it below and let me know what you think:

An unhandled exception has been thrown: OCP\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)

I Googled the entire text message and I am thinking maybe my PHP needs to be updated after reading the link below. But that makes no sense because I installed Ubuntu Server and the latest NextCloud version not too long ago.

https://github.com/nextcloud/server/issues/30292

I ran the command below to get information about the PHP version I have installed:

me@mysrvr:~$ php -version
PHP 8.1.2-1ubuntu2.11 (cli) (built: Feb 22 2023 22:56:18) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.2, Copyright (c) Zend Technologies with Zend OPcache v8.1.2-1ubuntu2.11, Copyright (c), by Zend Technologies

Any advice you or any fellow forum members can contribute as to why I am getting an unhandled exception error will be greatly appreciated.

php uses a different config file for local use and for apache.

this error has been posted before. please read trough post OCC doesn't work - #10 by lmsoren

see if you can spot a solution