OCC commands fail because __DIR__ apparently does not work

Nextcloud version: 20.0.4
Operating system and version: Debian GNU/Linux 10 (buster) - 1&1 Ionos Shared Hosting (!)
Apache or nginx version: unclear, commands to check don’t work
PHP version: 7.4

Nextcloud shows various issues with missing indices, keys, etc. It tells me to use occ command to fix those. OCC command execution causes immediate error.

I am on a shared hoster. I have SSH access, but NO sudo access. I can execute occ only by going into nextcloud/ directory and running it via ./occ, occ itself is not found as a command.

The Nextcloud version was just updated to the latest version, no change in behavior.

Steps to replicate it:

  1. Go to installation directory nextcloud/
  2. execute ./occ db:add-missing-indices


X-Powered-By: PHP/4.4.9
Content-type: text/html

<br />
<b>Fatal error</b>:  main() [<a href='function.require'>function.require</a>]: Failed opening required '__DIR__/console.php' (include_path='.:/usr/lib/php4.4') in <b>/homepages/13/d13526801/htdocs/nextcloud/occ</b> on line <b>11</b><br />

console.php file exists in the same directory as occ file. After I changed occ file import path to ‘console.php’ without __DIR__ , that error no longer appears, but the next comes immediately:

X-Powered-By: PHP/4.4.9
Content-type: text/html

<br />
<b>Parse error</b>:  syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in <b>/homepages/13/d13526801/htdocs/nextcloud/console.php</b> on line <b>38</b><br />

That line is also one where __DIR__ is used, so I assume that this is not supported? Maybe there is a simple workaround by setting this constant myself or something?

I tried define(__DIR__, "/homepages/13/d13526801/htdocs/nextcloud"); in OCC file, but that only fixed the first error, the second error in console.php still appears, so I assume that define() does not work globally.

Is there a way to set this globally or via command, I tried
__DIR__=/homepages/13/d13526801/htdocs/nextcloud ./occ db:add-missing-indices
but that changed nothing.

But I am not a linux expert so no idea how this is done “right”. Any help would be appreciated.

The output of your Nextcloud log in Admin > Logging: Nothing at all is added to log after executing the command

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

$CONFIG = array (
  'instanceid' => '<redacted>',
  'passwordsalt' => '<redacted>',
  'secret' => '<redacted>',
  'trusted_domains' => 
  array (
    0 => '<redacted>'
  'datadirectory' => '/homepages/13/d13526801/htdocs/nextcloud-data',
  'overwrite.cli.url' => '<redacted>',
  'dbtype' => 'mysql',
  'version' => '',
  'dbname' => '<redacted>',
  'dbhost' => '<redacted>',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => '<redacted>',
  'dbpassword' => '<redacted>',
  'logtimezone' => 'UTC',
  'installed' => true,
  'theme' => '',
  'maintenance' => false,
  'loglevel' => 2,
  'updater.release.channel' => 'stable',
  'updater.secret' => '<redacted>',

The output of your Apache/nginx/system log in /var/log/____:

Cannot find the directory, probably no access due to shared hosting restrictions.
I have a logs/ directory, but nothing is added after failed command execution.


If you run ./occ the default php version configured for the system is used. Prepend the right php version like /xyz/php7.4 ./occ to use a different php version.

Is another issue. The cgi/fpm php binary is used instead the cli binary.

I guess something like /usr/bin/php7.4-cli ./occ should work on your hosting account.

Thank you so much, that was exactly it, now it works perfectly :slight_smile:

I have a very similar error on 1&1 -
Fatal error: main() [function.require]: Failed opening required ‘DIR/console.php’ (include_path=’.:/usr/lib/php4.4’) in /homepages/35/d120461270/htdocs/nextcloud/occ on line 11

I am unclear where to make the change. is it in the occ file (mine has a single line as follows)

require_once __DIR__ . '/console.php';

I am lost. Have had NextCloud running for years, but starting to have some challenges.

I will answer my own question for reference
the error message really provided the answer. Even though I had the PHP set at 7.4, the default for the server was 4.4
confirmed with
php -v
PHP 4.4.9 (cgi-fcgi)

In accordance to https://community.1and1.com/using-php-composer-at-1and1/
I created a .profile file in my root directory with the following line :

alias php=’/usr/bin/php7.4-cli’

rechecked version - php -v

PHP 7.4.25 (cli)

then all the php files ran without additional edits