Cannot run OCC from a CLI

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud: 24.0.4
Operating system: Ubuntu 20.04
Apache: 2.4.41
PHP: 7.4.3

The issue you are facing:

Is this the first time you’ve seen this error? (Y/N): No

Steps to replicate it:

  1. try running suggested command lines (i.e. occ db:add-missing-indices)
  2. result: “Command ‘occ’ not found, but there are 21 similar ones.”
  3. running attempts (i.e. sudo -u www-data php occ -V)
  4. result: “Could not open input file: occ”
  5. spent last 3 days trying to figure out resolve to no avail.

The output of your Nextcloud log in Admin > Logging:

Warning	no app in context	Host 127.0.1.1 was not connected to because it violates local access rules	
2022-09-04T14:05:24-0500
Warning	no app in context	Host 127.0.1.1 was not connected to because it violates local access rules	
2022-09-04T14:05:24-0500
Warning	no app in context	Host 127.0.1.1 was not connected to because it violates local access rules	
2022-09-04T14:05:24-0500
Warning	no app in context	Host 127.0.1.1 was not connected to because it violates local access rules	
2022-09-04T13:45:08-0500
Warning	no app in context	Host 127.0.1.1 was not connected to because it violates local access rules	
2022-09-04T13:45:08-0500
Warning	no app in context	Host 127.0.1.1 was not connected to because it violates local access rules	
2022-09-04T13:45:08-0500
Warning	no app in context	Host 127.0.1.1 was not connected to because it violates local access rules	
2022-09-03T23:49:08-0500
Warning	no app in context	Host 127.0.1.1 was not connected to because it violates local access rules	
2022-09-03T23:49:08-0500
Warning	no app in context	Host 127.0.1.1 was not connected to because it violates local access rules	
2022-09-03T23:49:08-0500
Warning	no app in context	Host 127.0.1.1 was not connected to because it violates local access rules	
2022-09-03T22:57:10-0500
Warning	no app in context	Host 127.0.1.1 was not connected to because it violates local access rules	
2022-09-03T22:57:10-0500
Warning	no app in context	Host 127.0.1.1 was not connected to because it violates local access rules	
2022-09-03T22:57:10-0500

The output of your config.php file in :

<?php
$CONFIG = array (
  'instanceid' => 'xxx',
  'passwordsalt' => 'xxx',
  'secret' => 'xxx',
  'trusted_domains' => 
  array (
    0 => 'mycloud.example.com',
  ),
  'datadirectory' => '/mnt/sdb1/data',
  'dbtype' => 'mysql',
  'version' => '24.0.4.1',
  'overwrite.cli.url' => 'https://mycloud.example.com',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => 'xxx',
  'installed' => true,
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'mail_smtpmode' => 'smtp',
  'mail_smtpsecure' => 'tls',
  'mail_sendmailmode' => 'smtp',
  'mail_from_address' => 'xyz',
  'mail_domain' => 'hotmail.com',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpauth' => 1,
  'mail_smtphost' => 'smtp-mail.outlook.com',
  'mail_smtpport' => 'ppp',
  'mail_smtpname' => 'xyz@hotmail.com',
  'mail_smtppassword' => 'yyy',
  'default_phone_region' => 'US',
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'memcache.local' => '\OC\Memcache\APCu',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
);
```

The output of your Apache/nginx/system log in `/var/log/____`:
```
[Sun Sep 04 00:00:10.865011 2022] [mpm_prefork:notice] [pid 1448] AH00163: Apache/2.4.41 (Ubuntu) OpenSSL/1.1.1f configured -- resuming normal operations[Sun Sep 04 00:00:10.865029 2022] [core:notice] [pid 1448] AH00094: Command line: '/usr/sbin/apache2'

[Sun Sep 04 00:30:43.222453 2022] [mpm_prefork:notice] [pid 1448] AH00169: caught SIGTERM, shutting down

[Sun Sep 04 12:46:38.384806 2022] [mpm_prefork:notice] [pid 1439] AH00163: Apache/2.4.41 (Ubuntu) OpenSSL/1.1.1f configured -- resuming normal operations

[Sun Sep 04 12:46:38.386081 2022] [core:notice] [pid 1439] AH00094: Command line: '/usr/sbin/apache2'

[Sun Sep 04 13:19:25.579601 2022] [php7:error] [pid 1677] [client 62.171.157.68:51028] script '/var/www/cirus.devrod.com/html/wp-login.php' not found or unable to stat, referer: http://cirus.devrod.com/wp-login.php

[Sun Sep 04 14:22:25.155456 2022] [php7:error] [pid 1452] [client 78.159.119.207:42708] script '/var/www/beta.devrod.com/html/wp-login.php' not found or unable to stat, referer: http://beta.devrod.com/wp-login.php
```

Here is the occ documentation. Other documentation is found here as well.

https://docs.nextcloud.com/server/stable/admin_manual/configuration_server/occ_command.html

Yep, already read this, several times. Didn’t answer what, when, or how then. Doesn’t answer it now.

EXAMPLE: to Add missing indices it states “run following command: sudo -u www-data php occ db:add-missing-indices”.
That results in “Could not open input file: occ”. Regardless of what directory I run code. As a matter of fact, that’s the results I get for every code example I tried in that documentation.
This is why after days of trying to solve myself, I thought I’d see if someone with some experience using ‘occ’ could point me in the right direction or guide me to a resolution.

Thanks for the referral,

What was the exact command you entered to run occ?

The ones referenced in the opening statement “Steps to replicate” 1 & 3.

try either
sudo -u www-data php ./occ db:add-missing-indices or
sudo -u www-data php /var/www/nextcloud/occ db:add-missing-indices

(aniticpating that www-data is your webuser and owns all nextcloud-directories and files as well as nextcloud being intalled to that directory (it’s standard unless you changed it))

2 Likes

It’s not related to occ, but the error in the logfile is related to allow_local_remote_servers setting, which defines if connections from other applications running on same server are permitted. Looks something access your server from 127.0.0.1… e.g. Collabora or OnlyOffice: Error when trying to connect (Host violates local access rules)

All of that is actually answered in the first two paragraphs of that article.

What:

Nextcloud’s occ command (origins from “ownCloud Console”) is Nextcloud’s command-line interface. You can perform many common server operations with occ , such as installing and upgrading Nextcloud, manage users, encryption, passwords, LDAP setting, and more.

Where:

occ is in the nextcloud/ directory; for example/var/www/nextcloud on Ubuntu Linux.

How:

occ is a PHP script. You must run it as your HTTP user to ensure that the correct permissions are maintained on your Nextcloud files and directories.

In your steps to replicate, it looks like maybe you didn’t invoke php or something. You also didn’t mention your installation type (manual, docker, snap, etc.) which can make a big difference in how you run occ.

3 Likes

OK,
Ran both from server root as administrator and directly from the site path, got the following responses:
“An unhandled exception has been thrown:”
OCP\HintException: [0]: Memcache \OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)

Thought Memcache was installed when I ran sudo apt install memcached libmemcached-tools
Also configured memcached.conf for IPv6, & UDP.

MORE ABOUT INSTALLATION:
I installed to a headless server from a remote terminal, manually.
The server is my own hardware running several sites, my root domain and sub-domains. Nextcloud is installed to sub-domain.domain.com in the nextcloud directory.

I am trying to resolve the issues from setting/overview:

"The database is missing some indexes. Due to the fact that adding indexes on big tables could take some time they were not added automatically. By running “occ db:add-missing-indices” those missing indexes could be added manually while the instance keeps running. Once the indexes are added queries to those tables are usually much faster.

Missing index "fs_id_storage_size" in table "oc_filecache".
Missing index "fs_storage_path_prefix" in table "oc_filecache".
Missing index "properties_pathonly_index" in table "oc_properties".
Missing index "job_lastcheck_reserved" in table "oc_jobs".
Missing index "direct_edit_timestamp" in table "oc_direct_edit".```"

The issue you originally had jumped out at me right away.

“occ” isn’t an executable file, it’s a script that must be run by PHP. Secondly, “occ” isn’t in your path, you must be clear where the occ script is.

In your first example, you’re trying to run occ as if it’s executable, which it isn’t. You must use PHP to run it (like you did in the second example). The error message makes this explicit - “command occ not found”, because it isn’t an executable command.

However, in your second example, you didn’t use the full path (or “./occ” from within the Nextcloud directory). PHP “could not open the input file” because you didn’t tell it where occ was. You assumed it was in your path, but it isn’t.

I don’t know why you spent three days trying to figure this out, when the error messages explicitly told you what you were doing wrong.

1 Like

Your attitude here isn’t helping you.

2 Likes

What does that mean? You “ran both”? “Directly from the site path”? What commands exactly did you run, and where did you run them from?

Because the commands you posted in your original question could only produce the errors you also posted.

Also, you really shouldn’t be running any of these commands as root, because even if they appear to succeed, the Nextcloud instance may not have access to updated/altered data. That’s probably why Nextcloud is now having trouble accessing memcache.

1 Like

The error message gives you a hint that the matching PHP module for APCu might be missing. Did you check whether it is is installed? The following command shows a list of all “compiled” PHP modules on your system:

php -m

If it is not listed, try to install it:

sudo apt install php-apcu

Memcached has nothing to do with APCu. According to your config.php you have configured APCu as a local cache and Redis as distributed cache and for file locking. So installing memcached will not help you in any way… Memory caching — Nextcloud latest Administration Manual latest documentation

1 Like
  1. a. [DarkSteve]“What does that mean? You “ran both”? …”;
    Ans: Was a reply to JimmyKater’s suggestions.
    b. “Also, you really shouldn’t be running any of these commands as root”;
    Ans: Ran them from my login which is a member of the admin & www-data groups, from root path, explicitly pointing to the occ path and from nextcloud’s root path, in my case is var/www/subdomain.domain.com/html/nexrtcloud.where a text document named occ resides. if this is not correct then please point me in the right direction
    c. “I don’t know why you spent three days …when the error messages explicitly told you…”
    Ans: I’m a retired IT administrator, not a PHP programmer so, pardon my ignorance. I came here for help, not judgements.
  2. [bb77] “…Did you check whether it is is installed?”; Yes, it is.

Thanks, I’ll work on these suggestions.

I configured this way because the documentation you referred to instructed me to. If this is not the correct configuration, what is?

I never said the config was wrong. What I was trying to say is that if you have Redis and APCu configured in your config.php, then APCu and Redis must also be installed. But in this post you are talking about installing Memcached.

Memcached could be used as an alternative to Redis for the purpose of a distributed memory cache. But since you have already configured Redis for this purpose, according to the config.php in your opening post, you don’t need Memcached. And more importantly, the fact that Memcached wasn’t installed, has nothing to do with the APCu error message you get when you try to run the OCC command.

1 Like

Thanks for clearing that up.

Got the issue resolved. Did a clean install from latest version. Moved everything out of /nextcloud to domain root and sudo -u www-data php /var/www/subdomain.domain.com/occ db:add-missing-indices worked perfect.
Still have 1 warning “configure a memcache”. But, that discussion was a side step from the OCC issue and I’ll deal with that issue when I return from vacation.
Thanks everyone for the help. I apologize for letting my frustration get the better of me.
Adios :wave:

1 Like

It’s worked for me

1 Like