Nextcloud does not allow moving the data folder?

Okay so far.

Now ls -l of the …./Nextcloud/config folder.

The error message it shows you is specifically that it is not the right owner you use for sudo

Yes. This is all accurate.

I suspects that after manually editing the config.php, it has changed ownership.

sudo chown -R www-data:www-data /var/www/nextcloud

I forgot to mention i ran Vincent’s commands shown below he previosly posted. So maybe that changed the user owner? However, his OCC command never worked due to a handling error.

setting the user we use

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

setting the file we use

sudo chmod 750 /mnt/8TBdata

But i don’t follow how the config.php file got changed because i have not changed it using NANO txt editor.

Never the less your system reported that the nextcloud config file is not owned på www-data but is owned by root. This has to be changed. My command makes sure that all files in Nextcloud and underneath, is owned by correct user.

www-data also needs to own the data folder and below.

Kerasit,
Sorry, I did not include the following in my last post. Below is the result I got after running the command line you specified which is the
ls -l command line
to the NextCloud config folder path below:
/var/www/nextcloud/config/

me@mysrvr:~$ ls -l /var/www/nextcloud/config/
total 76
-rw-rw---- 1 root     www-data   837 Mar 20 02:02 config.php
-rw-r--r-- 1 www-data www-data 72711 Feb 23 10:30 config.sample.php

It clearly shows the config.php file is owned by “root” user and not “www-data” user. So this is a problem.

If I understand you correctly, running the command line below should change the “root” owner to “www-data” owner.
sudo chown -R www-data:www-data /var/www/nextcloud

After that is done your command line below should work without a problem:

sudo -u www-data php --define apc.enable_cli=1 /var/www/nextcloud/occ maintenance:mode --on

I will try it tomorrow.

This is the issue. In fact the owner and chmod settings is not accordingly to recommended for Nextcloud. But they will be fixed with an update - if ownership is correct.

Read this thread:

Kerasit,
Thank you for your post. Here is my update.

Step #1:
I successfully changed the “root” ownership to “www-data” ownership as shown in command lines below:

me@mysrvr:~$ sudo chown -R www-data:www-data /var/www/nextcloud
[sudo] password for me:
me@mysrvr:~$ ls -l /var/www/nextcloud/config/
total 80
-rw-rw---- 1 www-data www-data   838 Apr  1 17:33 config.php
-rw-r--r-- 1 www-data www-data 74456 Mar 21 09:20 config.sample.php

Step #2:
I then was able to successfully change to maintenance mode as shown in command line result below. This was not possible before due to a unhandled error. But now it works and thank you for your help with this command line.

me@mysrvr:~$ sudo -u www-data php --define apc.enable_cli=1 /var/www/nextcloud/occ maintenance:mode --on
Maintenance mode enabled

Step #3:
I then used the command line below to copy the existing data to it’s new location:
me@mysrvr:~$ sudo -u www-data cp -r /var/www/nextcloud/data/. /mnt/8TBdata/

Step #4:
I then used the command line below to set my new data location and I got the unhandled error shown below:

me@mysrvr:~$ sudo -u www-data php /var/www/nextcloud/occ config:system:set datadirectory --value=/mnt/8TBdata
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?)

Step #5:
I disabled maintenance mode using the command line shown below:

me@mysrvr:~$ sudo -u www-data php --define apc.enable_cli=1 /var/www/nextcloud/occ maintenance:mode --off
Maintenance mode disabled

My new problem is at Step #4. Do you or anybody in the forum have any advice on what is the correct command line I need to use to set my new data location successfully? Any information will be greatly appreciated. Thank you for your time.

Have you tried just changing 'datadirectory' => '/var/www/nextcloud/data' in your config.php to 'datadirectory' => '/mnt/8TBdata'?

1 Like

Until you sets the apc.enable_cli=1 in the correct config file, please use that —define parameter for all OCC calls you do. Step 4: add the —define apc.enable_cli=1 like you did with maintenance mode.

Rawtaz, thank you for your post. Below I have posted my config.php file located on my Ubuntu Server located at the /var/www/nextcloud/config directory. I removed what I think is sensitive data and replaced it with the word “removed”. As you can see ROW 10 shows I already have datadirectory' => '/mnt/8TBdata parameter configured in my config.php file.

The problem is when I type the command line below to see what directories are inside /mnt/8TBdata I get the Permission denied message shown below:

me@mysrvr:/$ cd /mnt/8TBdata
-bash: cd: /mnt/8TBdata: Permission denied

However, the command line below allows me to see the 8TBdata folder owner is www-data. But I cannot look inside the folder even if I use sudo cd /mnt/8TBdata. I’m not experienced enough to understand why I do not have access to the /mnt/8TBdata directory not even if I use SUDO and my Ubuntu root password.

me@mysrvr:/$ cd /mnt/
me@mysrvr:/mnt$ ll
total 12
drwxr-xr-x  3 root     root     4096 Mar 19 20:53 ./
drwxr-xr-x 18 root     root     4096 Mar  5 13:46 ../
drwxr-x---  8 www-data www-data 4096 Apr  1 17:52 8TBdata/
<?php
$CONFIG = array (
  'instanceid' => 'removed',
  'passwordsalt' => 'removed',
  'secret' => 'removed',
  'trusted_domains' =>
  array (
    0 => '1xx.xxx.x.xxx',
  ),
  'datadirectory' => '/mnt/8TBdata',
  'dbtype' => 'mysql',
  'version' => '26.0.0.11',
  'overwrite.cli.url' => 'http://1xx.xxx.x.xxx',
  'dbname' => 'removed',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.removed' => true,
  'dbuser' => 'removed',
  'dbpassword' => 'removed',
  'installed' => true,
  'default_phone_region' => 'US',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'updater.secret' => 'removed',
);

Kerasit, thank you for your post. Below I have posted my config.php file located at the /var/www/nextcloud/config directory in my Ubuntu server. May you please take a look at the last row where I added the apc.enable_cli=1. Does it look correct to you? Also how many more config.php files require I make the same change to them?

Also, I noticed two PHP.ini files exist at the two locations below:
/etc/php/8.1/cli/
/etc/php/8.1/apache2/

Do these two PHP.ini files also require I add to them the code shown below?
apc.enable_cli=1

<?php
$CONFIG = array (
  'instanceid' => 'removed',
  'passwordsalt' => 'removed',
  'secret' => 'removed',
  'trusted_domains' =>
  array (
    0 => '1xx.xxx.x.xxx',
  ),
  'datadirectory' => '/mnt/8TBdata',
  'dbtype' => 'mysql',
  'version' => '26.0.0.11',
  'overwrite.cli.url' => 'http://1xx.xxx.x.xxx',
  'dbname' => 'removed',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.removed' => true,
  'dbuser' => 'removed',
  'dbpassword' => 'removed',
  'installed' => true,
  'default_phone_region' => 'US',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'updater.secret' => 'removed',
  'apc.enable_cli=1',
);

Not config.php

For now just execute all occ commands with the define parameter to php

sudo -u www-data php --define apc.enable_cli=1 /var/www/nextcloud/occ

That includes your step 4. From above.

When you have done that and all your occ commands has been successfull and your nc works again, we can look at adding that apc.enable_cli=1 to the correct php.ini file (not config.php).

Seems like there are two separate things being discussed here:

  • Enabling APC for the CLI seems relevant only to run occ in the CLI, but should have nothing to do with making Nextcloud access the correct/new data folder path.
  • And then there’s the making NC able to access that new data folder path issue.

If you as root (sudo should be fine as long as you verify that you are really root when you do it, e.g. by sudo id) try to cd into and ls in the new data path, what do you get? If that isn’t working, then there’s some serious problems somewhere xD

How is that /mnt/8TBdata drive mounted, what filesystem is it, etc? It seems very odd that you cannot access it as root, if that is the case.

Yes.

There are Two main things:

Folder rights to new path. And if apcu cache is defined in config.php then OCC also needs apcu to be enabled.

First thing:
Sudo Chown www-data:www-data -R /mnt/8TBdata

Second:
Ensure apc as that is needed in order to do OCC (which will tremendously enhance support and managing the system). When we can do OCC commands without hickups (by using the —define parameter we ensures that it will be enabled regardless of missing ini config).
When we can predict excactly how the system will react based on OCC - every time - we can experiment with/find the right ini file to add the apc.enable_cli=1 to the very bottom. This is needed for clean cron job anyway.

This is the two things that needs to be done.
Why it has taken so Long time to help, is that none of us thought about the config.php had changed owner to root when everything else was still owned by www-data.

So:
For now, ANY Cli command you do that has PHP in it, always have that —define apc.enable_cli=1 until we have added that one to the correct .ini file. We will look at that when your Nextcloud is up and running on new path.

Now when we are in control with and on top of apc on cli, we can execute the move of files.

You don’t need occ and APC and stuff in the CLI just to tell NC where the data resides. That’s my point. As long as APC is loaded correctly in the non-CLI part of PHP, it should be fine (or you can just disable APC entirely for now, it’s not needed for NC to function).

Yeah. But that means manually changing the config.php and that changed owner before. Safest is relying on OCC to make it cleaner, and OP has activated caching for Nextcloud. So right now the least intrusive and the things that introduces less risk of issues, is using OCC with current config and not touch config.php directly.

I see your reasoning but would not really think the same thing. But oh well, carry on :smiley:

in the mean time the config.php shows

not that it is relavant but running beta version.

Thank you to everybody for your postings. I have come to the conclusion it is best to configure your data directory location while performing Nextcloud wizard installation, as it is very difficult to move the data directory after Nextcloud wizard installation is completed. Especially, for users like me who are inexperienced. Therefore, I have decided to start from the beginning as outlined in the steps below:

Step 1: Erase 500GB NVME Boot drive and internal 8TB SSD secondary drive and reformat both drives to EXT4 format.

Step 2: Install the latest Ubuntu Server OS onto my 500GB NVME Boot drive.

Step 3: Mount 8TB SSD drive (I did not do that before. I mounted the SSD after Nextcloud was installed which was a big mistake). My new mount path wil be /mnt/8tbssd. And inside the 8tbssd directory I will make a “nxtcloud_data” directory and a “jellyfin_data” directory to store all of my personal data onto my 8tb SSD drive.

Step 4: Install Nextcloud HUB 4 Version 26. Hopefully this version has less bugs compared to what I am using right now which is Nextcloud version 25. Install PHP FPM or PHP? Install MariaDB, and install Apache 2. In short, I will refer back to the Nextcloud installation YouTube video at the link below which is what I followed for my first install:

https://www.youtube.com/watch?v=5IUKE3oA7AY

Step 5: Here is the important part. When I get to the point of the installation wizard shown in the screenshot below I will delete the “/var/www/nextcloud/data” path and instead use: “/mnt/8tbssd/nxtcloud_data”. I believe if I would have done this in my first installation I would have avoided a lot of the complications I have encountered within this particular forum thread as it relates to moving my Nextcloud data folder to a different drive.

Lastly, I hope anybody in this forum can please be so kind to post any opinion relating to what I need to do different for my second Nextcloud installation I did not cover in my Nextcloud installation steps 1 through 5 listed above. I would like to be able to install Nextcloud, Apache, PHP and MariaDB in the correct manner to avoid any complications that will prevent Nextcloud from working correctly within a local network environment (no outside WWW access needed).

Thank you for your time.

Seems completely overkill to me but I understand that if you feel this is the most controlled and simplest way for you, then that is a decision that makes sense for your situation, so go for it if it makes you sleep well! :slight_smile: