[Solved] occ "Your data directory is invalid."

Hi there.
Unfortunately, I’m facing a problem that I can’t solve with existing threads and solutions. It is regarding occ running on a shared hosting.
When I run an occ command on the shell (for example occ files:scan --all) it aborts with the message:

Your data directory is invalid.
Ensure there is a file called “.ocdata” in the root of the data directory.

Cannot create “data” directory.
This can usually be fixed by giving the web server write access to the root directory. See https://docs.nextcloud.com/server/24/go.php?to=admin-dir_permissions

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /nextcloud-root/lib/private/Console/Application.php:164
Stack trace:
#0 /my.qult.de/console.php(99): OC\Console\Application->loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 /my.qult.de/occ(11): require_once(‘/nextcloud-root/con…’)
#2 {main}

The data folder is set outside the web root
'datadirectory' => '/home/httpd/vhosts/my-domain/nextcloud-data',
And the root folder ist
/home/httpd/vhosts/my-domain/nextcloud-root

I run the occ command with my ssh user like ./occ ... and php occ ....
I get the same error as well as when I change the data directory to 'datadirectory' => '/home/httpd/vhosts/my-domain/nextcloud-root',.

Is there any solution to run occ on a shared hosting with a regular ssh user?

Thank you for your help!

You need to run occ with the same user as the web server.

https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/occ_command.html#http-user-label

Thank you @come-nc . I read this but I have no option to change the user when I’m logged in via ssh.
But, the ssh user has the right to read and write all folders.
Do you know if Nextcloud has a built-in feature to run occ commands through a web interface?

Ok. Then use the Nextcloud user and not the other user. Maybe you can use sudo -u nextcloudusername if sudo is correct configured.

Please do not use the ssh user. Use the Nextcloud user. E.g. files must created from the correct user. That is normal in linux.

You can install the app OCC Web. Please do not install and do not use the app. But this app is eexecuted from your Nextcloud user.

Maybe you must create the empty file .ocdata Use your Nextcloud user:
touch /home/httpd/vhosts/my-domain/nextcloud-data/.ocdata

Thank you @devnull for your time to answer. I appreciate it very much!

Unfortunately I have no other user than the ssh user. All files and folders are created with the same user.

I also checked the data folder and it has a an empty .ocdata inlcuded.

Why do you recommend not using OCC Web?

OCC must run in the context of the web server user, whatever that is (www-data or equivalent). This is a requirement.

If you don’t have access to this user on the system, it may not be suitable for running Nextcloud.

Hi guys. I could solve the issue.
It is NOT RELATED to the wrong user I’m using. I found this wiki Configure Nextcloud to make occ work in a restricted chroot environment - DiscordDigital Wiki
The solution was I had to change how to set up the data directory.
I changed the line from
'datadirectory' => '/home/httpd/vhosts/my-domain/nextcloud-data',
to
'datadirectory' => realpath(__dir__ . '/../../nextcloud-data'),
I’m glad it works now.

2 Likes