How do I use occ commands?

Dear all,

Can someone explain to me in simple terms how to use the occ commands?

I have full ssh access to my vps, but of course the occ command alone does not recognize my server.

Thanks in advance for your reply.

Rovanov

1 Like

Hey @Rovanov welcome to the Nextcloud community :waving_hand:

You posted your request in the support category. Unfortunately you ignored the template and a lot of information to help you is missing. Please edit your original post and add all required details like Nextcloud version, webserver type and version, os version, related log file content. Use the support template.

Without additional information the community members cannot help you.

Meanwhile see if the docs help:

1 Like

Hello scubamuc,

Thank you for your response.

You are correct, I did not use the message template. I will pay attention to this next time.

Since my question is not about a specific NC installation, I did not think it was useful to post all kinds of unnecessary details.

My simple question is how to execute an occ command.

When I enter “occ” in my ssh-terminal, the server has no idea what is required.

So how do I tell my server what occ means?
Do I need to add something else before?
Which command should I enter in my SSH terminal?
What does it look like?
Can someone give me an example?

Of course, I have read the documentation, but I don’t quite understand it.

Thank you for your response.

Hmm…

…seems pretty specific to me. :wink:

Yes.

Most likely even the exact command, if you weren’t so secretive about the installation method you used and the operating system you’re running.

If you are running a Nextcloud AIO, then you use variant 1. If you are using a Nextcloud with a LAMP stack, then you use variant 2.

Variant 1:

“sudo docker exec --user www-data nextcloud-aio-nextcloud php occ”

Variante 2:

Change to the Nextcloud directory, for example: “cd /var/www/nextcloud/”

and then “sudo -u www-data php occ”

Yeah, and then there are different distros where the www user is named differently. Then there’s the Snap, Nextcloud AIO, Nextcloud PI. etc… etc.

I mean, why can’t people at least tell us what OS they are running and what installation method they used? In my opinion, it shouldn’t be possible to post here without providing that information at least.

Sorry, not meant to be offensive, but sometimes I do wonder what people expect from us here.

@Rovanov By the way, if you want to remain unspecific, A.I. is perfect for that, and you can ask and receive unspecific questions and answers all day long.

Sorry for the little rant. :wink:

A simple way is to install and use the “OCC Web” app, see

I used it several times after NC upgrades for entering requested commands like

db:add-missing-indices
files:scan --all
maintenance:repair --include-expensive

and it always worked fine!

1 Like

And, by the way, and I don’t mean this specifically for the OP, but rather for everyone who seems to think we’re their personal entertainers. if you just need a few examples, AI is actually perfect for that. I mean that seriously.

Or you could just google “how to use the Nextcloud occ command,” and you’ll instantly get hundreds of examples right in your browser.

I don’t want to sound elitist, but if someone would rather write two long stories in a support forum than simply mention what OS they’re using and how they installed Nextcloud, then a lack of time clearly isn’t the issue. In that same amount of time, they could’ve just filled out the support template, at least as much as possible without the occ output, obviously. :wink:

/rant :wink:

@Rovanov I’m still ready to help you out, if you provide us with the necessary information. :slight_smile:

Okay, I hadn’t considered the SNAP version. And yes, the more information you have, the easier it is to help.

But sometimes it’s made too complicated. Of course, he might have to adjust a few things in my examples, but he’ll certainly be aware of that, especially what he needs to adjust.

I thought I’d just help him out with a quick, simple answer to a quick, simple question. :person_shrugging: Sorry, my mistake :person_facepalming:

That’s actually not the best advice, since the OCC Web app hasn’t really been maintained for quite some time. It can also potentially break things if you run a long-running command that writes to the database and the process times out, for example, if your browser crashes or the connection drops.

@Rovanov

The occ command is a PHP script that needs to be run in the context of the web server user.

On Debian/Ubuntu systems, that user is usually www-data.

In theory, you could make the occ script executable and rely on the shebang line to run it like any other script on a POSIX-compatible system with the correct interpreter/executable, but that’s not recommended.

Instead, you should explicitly tell the system to run it with the PHP CLI executable as the web server user.

Here’s how you would typically do that on Debian or Ubuntu:

sudo -u www-data php /path/to/nextcloud/occ <command>
  • sudo -u www-data - runs the command as the web server user (www-data).
  • php - invokes the PHP CLI interpreter / php executable
  • /path/to/nextcloud/occ - path to the OCC script in your Nextcloud installation directory.
  • <command> - the OCC command you want to execute (for example, maintenance:mode --on).

There migt be situations where you need to provide the full path to the php executable as well, for example, on systems with multiple PHP versions installed or in ceratin webhosting environments.

If you don’t want to type that entire command every time, you can create a bash alias (or the equivalent in other shells, like zsh or fish).

For example, in bash, add this line to your ~/.bashrc file:

alias ncc='sudo -u www-data php /var/www/nextcloud/occ'

Then you can simply run:

ncc <command>

to execute OCC commands more conveniently.

If you’re using a different shell or OS, just search online (or ask an AI assistant :wink:) to find out how to create command aliases for your environment. Or, you could tell us which OS you installed Nextcloud on and which installation method you used.

Hope this is of any help. :slight_smile:

I see your point, but it is difficult for beginners (and lesser experienced users) to see the potential dangers here: The OCC Web app was updated only half a year ago (which isn’t really that long) and there are no hints like “potentially dangerous, use at your own risk and not without a fresh backup” or something like that on the app page in the app store.

It may be a third party app and not an “official” app provided by the Nextcloud team, however many “naive” users (like me) may take it for granted the apps listed in the NC app store may be used without any fears of encountering loss of data…

GitHub - Adphi/occweb is literally full of :warning: -signs. In fact, every section of the Readme is basically a warning :wink:

But yeah, that should also be mentioned here: OCC Web - Apps - App Store - Nextcloud