Occ command not found?

When I want to run the advised command on my Nextcloudpi it cant find the command:

root@nextcloudpi:~# occ db:add-missing-indices
-bash: occ: command not found

anyone an idea?

By default this command is not in the search path and might not have executable rights. Change to the Nextcloud root directory and check if the command exists in that directory.

I tried multiple directorys (var/www…) Wich one do you mean in detail?

You have to execute the occ command in the directory you installed your nextcloud in.

If you installed your Nextcloud into your /var/www/nextcloud folder your have to be in /var/www/nextcloud

From the command you posted it seems that you try to execute occ in the home directory of the root user.

What is your Setup? How did you install Nextcloud?

:~$ sudo find / -name "occ"

Could help you find the real location.

1 Like

@crustulumtheone You might also be interested in the admin docs for running the OCC command - notably, it should be run as your web user (whatever user is running Apache/nginx).

As an example, here’s how I run OCC on my Ubuntu setup:
sudo -u www-data php /var/www/nextcloud/occ
I could leave out the ‘php’ part, but this way I don’t have to worry about setting execute permissions.


Hi, can you explain this command a bit?
sudo -u www-data php /var/www/nextcloud/occ

Why wouldnt sudo -u www-data /var/www/nextcloud/occ not work? Thanks!

btw, your answer works!

because you must run php as user www-data which in turn runs occ

occ is not an executable binary but must be interpreted by php

1 Like

To expand on @Ascendancer 's correct answer:
Usually it works just fine to call the occ command directly, because the beginning line tells your shell to run it through the PHP interpreter, like this:

<PHP code that will be interpreted by the program linked above>

You can use just about any command as an interpreter (/bin/sh is the most common one for generic shell scripts), but in order for this to work, the current user has to have ‘execute’ permission on the file itself, as well as the interpreter.

I’ve had several times after updates in the past, where I didn’t have execute permissions as any user. It’s easy to fix (sudo chmod +x occ), but I got in the habit of treating it as non-executable and just calling the interpreter directly. I give that out as the preferred command just in case anyone else has the same issue.
For what it’s worth, I don’t think I’ve had that issue with the automatic installers for NC17+, maybe even since NC15, but it might crop up with manual upgrades or other package installers.


You can also use it like this:

php console.php db:add-missing-indices

when you are in de SSH session and folder of your Nextcloud setup


Unfortunatly, for me that isn’t working. When executing this command, I get one line with the Name of my nextcloud-installation and the version (19.0.0). And then the following:

and so on…

What am I doing wrong?!


NCP users can use:

ncc db:add-missing-indices

ncc is Nacho’s occ wrapper, it ‘knows’ the path to occ, to run as www-data and use php to execute. Neat :wink: (Use sudo if not root)

non-ncp would need to pass the full command

php /var/www/nextcloud/occ db:add-missing-indices

1 Like

A post was split to a new topic: Occ command not found