Error when changing location of data directory


My Nextcloud install is quite new and I read here that I should have my data directory outside of the web root.

Hence I moved /var/www/nextcloud/data/ to /home/username/nextcloud/data and changed /var/www/nextcloud/config/config.php to:

$CONFIG = array (
  'trusted_domains' => 
  array (
    0 => 'localhost',
    1 => '',
  'datadirectory' => '/home/username/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '',
  'overwrite.cli.url' => 'http://localhost',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'oc_admin',
  'installed' => true,
  'instanceid' => 'ocagznenjk6c',
  'maintenance' => false,

Note that my files are accessible from the Nextcloud web interface; it seems that my change largely worked.

However, in my Nextcloud web interface, in “Administration → Overview → Security & setup warnings” I have a message in red that reads (translated):

It was not possible to execute the cron job via CLI. The following technical errors have appeared:
    Your directory is not valid; make sure your data directory contains a file named ".ocdata" at its root.

Here is what my directories look like:

$ ls -l /home/username
drwxr-xr-x 3 www-data www-data      4096 Sep 16 08:11 nextcloud

$ ls -l /home/username/nextcloud
drwxrwx--- 5 www-data www-data      4096 Sep 16 08:10 data

$ ls -l /home/username/nextcloud/data
drwxr-xr-x  4 www-data www-data  4096 Sep 15 14:46 admin
drwxr-xr-x 10 www-data www-data  4096 Sep 16 08:00 appdata_hashdata
drwxr-xr-x  5 www-data www-data  4096 Sep 16 08:09 example
-rw-r--r--  1 www-data www-data   542 Sep 14 12:13 .htaccess
-rw-r--r--  1 www-data www-data     0 Sep 14 12:13 index.html
-rw-r-----  1 www-data www-data 36847 Sep 15 19:50 nextcloud.log
-rw-r--r--  1 www-data www-data     0 Sep 14 12:13 .ocdata

As you can see the data directory does indeed contain the .ocdata file.

Does anyone have an idea what is going on?
Thanks in advance for your help.

Nextcloud version:
Operating system and version: Debian 11
Apache or nginx version: nginx 1.18.0
PHP version: 7.4

This looks like a permission issue. Does www-data have permission to read off the /home folder?

Run the following command to determine users with access to your data directory.

ls -ld /home/username/nextcloud/data

Is www-data listed?

All of my nextcloud servers are set up so the data folder is outside of nextcloud; located at /var/www/. If you move your data back to /var/www/data I’m guessing your access issues will be resolved.


Did you also change the oc_storages table in the database:

Thank you all for your support. In the end I decided to start from scratch as I only did the installation a few days ago.

I did manage to move my data directory out of the web root, as the occ script has a way to specify where it should be placed at install time.