[SOLVED] Can't run occ properly. Need to point specific directory

Nextcloud version 14.0.4:
Operating system and version Ubuntu 18.04:
Apache or nginx version Apache 2.4.29:
PHP version 7.1.2:

xx@xx:~$ sudo cat /var/www/html/nextcloud/config/config.php

<?php
$CONFIG = array (
  'instanceid' => 'xx',
  'passwordsalt' => 'xx,
  'secret' => 'xx,
  'trusted_domains' => 
  array (
    0 => '192.168.0.138',
    1 => 'xx',
    2 => 'xx',
    3 => 'xx',
  ),
  'datadirectory' => '/mnt/files/data',
  'overwrite.cli.url' => 'https://192.168.0.138',
  'htaccess.RewriteBase' => '/',
  'dbtype' => 'mysql',
  'version' => '14.0.4.2',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'alex.root',
  'dbpassword' => 'xx',
  'installed' => true,
  'skeletondirectory' => '',
  'auth.bruteforce.protection.enabled' => true,
  'mail_from_address' => 'nextcloud',
  'mail_smtpmode' => 'sendmail',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_domain' => 'xx',
  'maintenance' => false,
  'updater.secret' => 'xx',
  'theme' => '',
  'loglevel' => 2,
  'updater.release.channel' => 'stable',
);

When I run occ comand I have this issue

xx@xx:~$ sudo -u www-data php occ maintenance:mode --on
Could not open input file: occ

But it works when I use

sudo -u www-data php /var/www/html/nextcloud/occ maintenance:mode --on

Is it bad?
How to make work occ as usual?

Hi,

It is not bad; not at all. It’s the same for me, for years :slight_smile:

If I’m not mistaken, you can make it work, by adding your nextcloud folder to the PATH environment variable. But it’s only worth it, if you don’t want to - by no means - enter the path every time. However, I guess you won’t call the occ command that often.

1 Like

you can call the occ while your in the directory!

cd /var/www/html/nextcloud/
sudo -u www-data php occ maintenance:mode --on

3 Likes

Thank you!

Perfect! I was facing an error e this worked for me, thanks!