OCC without sudo

Hi,

I am running nextcloud on a webhosting with a shell but without sudo rights. This keeps me away from running any OCC command and since I am running a newer NC instance, the OCC application is not working.

If I run the OCC command from shell without sudo I get:

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 webserver write access to the root directory. See https://docs.nextcloud.com/server/22/go.php?to=admin-dir_permissions

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /home/3d-sphere.com/sub/sylex.repository/lib/private/Console/Application.php:162
Stack trace:
#0 /home/3d-sphere.com/sub/sylex.repository/console.php(98): OC\Console\Application->loadCommands()
#1 /home/3d-sphere.com/sub/sylex.repository/occ(11): require_once('/home/3d-sphere...')

The .ocdata is present in the directory it is just not working. I have tried to follow the method of creating a php file with the occ command but it is not doing anything.

<?php 
   exec("/usr/bin/php7.4 -d memory_limit=1024M ../sylex.repository/occ db:add-missing-indices > occ-result.txt");
exec("echo \"Command completed!\" >> occ-result.txt");
   header('Location: occ-result.txt');
?>

I get command complete but without any change. If I try to run the php file from the shell, I get the “Your data directory is invalid” as above. I am still not sure if the relative occ path is set right. The php file sits in a folder sub/occ. The nextcloud instance sits in sub/sylex.repository folder.

Any help would be appreciated, I have no idea how to solve this.

thx, tomas

Which owner is active while using the shell?
Is the user different to your account user?

Shared hosting is a challenge …

Hi, thank you for your answer.

It is everytime a new generated user starting with “uid…”. The connection is alive for 1hour and then a new user is created, etc… The permision for each folder in the nextcoud instance is set to this new created user. Dont know if this information helps.

tomas

It does not help to solve it for you. It helps to understand what is happening. From my understanding occ command should work without sudo.
Have you tried to contact your hosters support? NC is getting really popular over the last years and many hosters know it.

thx for your answer, yeah I would guess the same but it is not.
I will contact the hosting as you suggest, thx, and hopefully will solve it!

thx a lot for your help!

@tsalat
On some systems you can not use php exec.

Sometimes you do not need sudo -u webservername because the webspace runs in the content of the normal user.

Instead of
sudo -u www-data php occ ...
use
php occ ...
(change before in the correct path where occ is listed)

Post errors.

hi, I get this error running the command like: php occ …

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 webserver write access to the root directory. See https://docs.nextcloud.com/server/22/go.php?to=admin-dir_permissions

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /home/3d-sphere.com/sub/sylex.repository/lib/private/Console/Application.php:162
Stack trace:
#0 /home/3d-sphere.com/sub/sylex.repository/console.php(98): OC\Console\Application->loadCommands()
#1 /home/3d-sphere.com/sub/sylex.repository/occ(11): require_once('/home/3d-sphere...')

Create an empty file .ocdata in your nextcloud data directory ../../data.

Post the rights of the nextcloud dir.

hi devnull,

here is the output from the nextcloud root directory:

uid27767@shellserver:~/3d-sphere.com/sub/sylex.repository$ ll
total 343
drwxr-xr-x 14 uid27767 gid27767    29 Mar  1 19:03 ./
drwx------ 14 uid27767 gid27767    14 Mar  1 19:03 ../
-rw-r--r--  1 uid27767 gid27767  3252 Feb 28 20:07 .htaccess
-rw-r--r--  1 uid27767 gid27767   101 Feb 28 20:01 .user.ini
drwxr-xr-x 44 uid27767 gid27767    51 Feb 28 20:04 3rdparty/
-rw-r--r--  1 uid27767 gid27767 19327 Feb 28 20:01 AUTHORS
-rw-r--r--  1 uid27767 gid27767 34520 Feb 28 20:01 COPYING
drwx---r-x 54 uid27767 gid27767    54 Feb 28 20:04 apps/
drwx---r-x  2 uid27767 gid27767     6 Feb 28 20:07 config/
-rw-r--r--  1 uid27767 gid27767  3924 Feb 28 20:01 console.php
drwxr-xr-x 22 uid27767 gid27767    28 Feb 28 20:04 core/
-rw-r--r--  1 uid27767 gid27767  5163 Feb 28 20:01 cron.php
drwxrwx--- 12 uid27767 gid27767    17 Feb 28 20:42 data/
-rw-r--r--  1 uid27767 gid27767   156 Feb 28 20:01 index.html
-rw-r--r--  1 uid27767 gid27767  3455 Feb 28 20:01 index.php
drwxr-xr-x  6 uid27767 gid27767     9 Feb 28 20:04 lib/
-rw-r--r--  1 uid27767 gid27767   283 Feb 28 20:01 occ
-rw-r--r--  1 uid27767 gid27767    19 Mar  1 18:12 occ-result.txt
drwxr-xr-x  2 uid27767 gid27767     3 Feb 28 20:04 ocm-provider/
drwxr-xr-x  2 uid27767 gid27767     5 Feb 28 20:04 ocs/
drwxr-xr-x  2 uid27767 gid27767     3 Feb 28 20:04 ocs-provider/
-rw-r--r--  1 uid27767 gid27767  3139 Feb 28 20:01 public.php
-rw-r--r--  1 uid27767 gid27767  5340 Feb 28 20:01 remote.php
drwxr-xr-x  4 uid27767 gid27767     8 Feb 28 20:04 resources/
-rw-r--r--  1 uid27767 gid27767    26 Feb 28 20:01 robots.txt
-rw-r--r--  1 uid27767 gid27767  2452 Feb 28 20:01 status.php
drwx---r-x  4 uid27767 gid27767     5 Feb 28 20:04 themes/
drwx---r-x  2 uid27767 gid27767     4 Feb 28 20:07 updater/
-rw-r--r--  1 uid27767 gid27767   422 Feb 28 20:01 version.php

here the output from the /data directory, the .ocdata file was there and I even tried to delete it and create a new one. The same error as in my previous post:

uid27767@shellserver:~/3d-sphere.com/sub/sylex.repository/data$ ll
total 20125
drwxrwx--- 12 uid27767 gid27767       17 Feb 28 20:42  ./
drwxr-xr-x 14 uid27767 gid27767       29 Mar  1 19:03  ../
-rw-r--r--  1 uid27767 gid27767      542 Feb 28 20:07  .htaccess
-rw-r--r--  1 uid27767 gid27767        0 Feb 28 20:42  .ocdata
drwxr-xr-x  7 uid27767 gid27767        7 Aug 27  2021  __groupfolders/
drwxr-xr-x  6 uid27767 gid27767        6 Apr 14  2020  admin/
drwxr-xr-x 15 uid27767 gid27767       15 Jan 13 10:52  appdata_oc6c02mgpnho/
drwxr-xr-x  4 uid27767 gid27767        4 Apr 11  2020 'e.noordermeer@fugro.com'/
drwxr-xr-x  2 uid27767 gid27767        3 Sep 26 17:06  files_external/
-rw-r--r--  1 uid27767 gid27767        0 Feb 28 20:07  index.html
drwxr-xr-x  5 uid27767 gid27767        5 Apr  8  2021  j.demuth/
drwxr-xr-x  4 uid27767 gid27767        4 Apr 15  2020 'n.buggenhout@fugro.com'/
-rw-r-----  1 uid27767 gid27767 20155869 Mar  2 12:35  nextcloud.log
drwxr-xr-x  5 uid27767 gid27767        5 May 10  2021  r.nieuwland/
drwxr-xr-x  8 uid27767 gid27767        8 Mar  1 08:08 'tsalat@sylex.sk'/
drwxr-xr-x  4 uid27767 gid27767        5 Feb 28 20:07  updater-oc6c02mgpnho/
-rw-r--r--  1 uid27767 gid27767   162113 Feb 28 20:07  updater.log

tomas

On my system the group has got write access (rwxrwx— → 770)
But i think that is not the problem.

I think Nextcloud searches somewhere the directorys and files at the wrong place.
The correct place is
/home/3d-sphere.com/sub/sylex.repository

Test:
cd /home/3d-sphere.com/sub/sylex.repository
php occ files:scan --all

If it not works post parts (e.g. datadirectory) from
/home/3d-sphere.com/sub/sylex.repository/config/config.php

Hi.

already tried to change the permisions but as you pointed out, it didnt made any difference.
I have tried the directory you have mentioned but got the same error as before, .ocdata not present, etc…

The data path in config is like this:

 'datadirectory' => '/nfsmnt/hosting1_2/1/b/1b762867-630f-4dca-b3dc-caca865f417b/3d-sphere.com/sub/sylex.repository/data',

tomas

Test to change it to:

'datadirectory' => '/home/3d-sphere.com/sub/sylex.repository/data',

Hi,

tried to change the path to the two ones below in the config file. The second path exists as well, a bit different to the one that was initially in the confing.php but present and accessible on the hosting.

'datadirectory' => '/home/3d-sphere.com/sub/sylex.repository/data',
'datadirectory' => '/nfsmnt/web-18/1/b/1b762867-630f-4dca-b3dc-caca865f417b/3d-sphere.com/sub/sylex.repository',

both result in the nextcloud instance not working and returning in the frontend:

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

however, and now the positive part, while changing the data path inside config to:

'datadirectory' => '/nfsmnt/web-18/1/b/1b762867-630f-4dca-b3dc-caca865f417b/3d-sphere.com/sub/sylex.repository',

the occ command went okey using:

php occ db:add-missing-indices

Hence, I have no idea why I am getting the error in the frontend while changing the data-path but at least it works as a workaround for the occ command, heh.

thx for your help, Tomas

1 Like

Sorry. But i think this path make normally no sense. This is no data dir (see your posts above). Sorry i do not understand it.

hi,

most likely I have added some confusion to the thread as well. I would try to summarize it for a better overview. So, the occ commands using the SSH do not woks by calling the command bellow. The reason is most likely the absence of SUDO rights or something else, not sure.

php occ files:scan --all

error 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 webserver write access to the root directory. See https://docs.nextcloud.com/server/22/go.php?to=admin-dir_permissions

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /home/3d-sphere.com/sub/sylex.repository/lib/private/Console/Application.php:162
Stack trace:
#0 /home/3d-sphere.com/sub/sylex.repository/console.php(98): OC\Console\Application->loadCommands()
#1 /home/3d-sphere.com/sub/sylex.repository/occ(11): require_once('/home/3d-sphere...')

@devnull suggested to verify the data directory inside the config.php file, the datadirectory entry in the configuration is:

'datadirectory' => '/nfsmnt/hosting1_2/1/b/1b762867-630f-4dca-b3dc-caca865f417b/3d-sphere.com/sub/sylex.repository/data',

This location does not exists on the server, if I look via SSH, however, the directory nfsmnt exists and include only one directory that at the endpoints as a link to the home directory:

'datadirectory' => '/nfsmnt/web-18/1/b/1b762867-630f-4dca-b3dc-caca865f417b/3d-sphere.com/sub/sylex.repository/data',
lrwxrwxrwx 1 root     root        5 Mar  3 13:58 1b762867-630f-4dca-b3dc-caca865f417b -> /home/

Changing the config.php and the ‘datadirectory’ entry with:

'datadirectory' => '/home/3d-sphere.com/sub/sylex.repository/data',

Will result at the frontend to an error message:

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

However, using the SSH the occ command will work although the frontend not :grinning:. Changing the ‘datadirectory’ to /home/3d-sphere.com/sub/sylex.repository/data will therefore result in OCC working via SSH and reverting back to the installation entry will result in the frontend to work after running the OCC.

I am not sure if this is understandable but this is how it behaves.

tomas

Ok.

Go in this directory:

And then post the output of:

readlink -f .ocdata

hi,

here is the output:


uid27767@shellserver:~/3d-sphere.com/sub/sylex.repository/data$ readlink -f .ocdata

/home/3d-sphere.com/sub/sylex.repository/data/.ocdata

I think than you must set:

'datadirectory' => '/home/3d-sphere.com/sub/sylex.repository/data',

in /home/3d-sphere.com/sub/sylex.repository/config/config.php
But it think you have tested it.
Check for multiple entries in config.php and delete them.

Still getting the same error in the frontend:

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

I think I will leave it as it is. At least I have some option on how to run the occ command although the site will be not working during that time. It is not a big deal.

tomas