Nextcloud is my on-premise cloud solution of choice. I use it for data and documents I don’t want shared on third-party services. Because Nextcloud is easy enough for any admin to install on off-the-shelf hardware, or on a cloud-hosted service, it makes for an ideal solution for any individual or business.
For the most part, Nextcloud installs and can be managed from within the GUI, which makes it even more user-friendly. However, there are times when you might find yourself either unable to access the GUI or there’s the rare task that can only be taken care of from the command line. When that occasion strikes, what do you do?
You use the occ command.
SEE: Cloud data storage policy (TechRepublic Premium)
What is the occ command?
Nextcloud stems from ownCloud, which included the ownCloud Console tool–hence occ. The occ tool is the command line interface which allows admins to manage things like upgrading Nextcloud, managing users, encryptions, passwords, LDAP, two-factor authentication, disabling apps, and more.
The thing is, occ isn’t the easiest command to use. You can’t just log in to your Linux server and issue a command like occ update. That, of course, is a shame, but it’s the reality of dealing with Nextcloud from the command line.
So, how do you use the occ command? Let’s find out.
How to use the occ command
In order to use occ, it must be run by the user associated with the installed web server. For instance, on Ubuntu Linux, the Apache user is www-data. On a Red Hat-based Linux distribution that user would be apache.
If you want to be certain as to the user on your distribution, make sure the Apache web server is running and issue the command:
sudo lsof -i | less
You should see either apache or www-data listed in the user column (Figure A).
How do we run a command as the Apache user? That would be like so:
sudo -u www-data COMMAND
sudo -u apache COMMAND
Where COMMAND is the command to be run.
The next bit of trickery is that the occ command must be run via php. Instead of just issuing:
sudo -u apache occ
We have to run it like so:
sudo -u apache php occ
Here’s another hurdle: If you just run that command from anywhere in the directory hierarchy, you’ll get an error because you must run the occ command from within the directory that houses Nextcloud. For example, in my installation, I issue the command from within /var/www/html/nextcloud. Make sure to change into the directory you’ve installed Nextcloud into.
Next, we tell occ what we’re doing. For example, say you want to know what version of Nextcloud is installed. You could issue the command:
sudo -u www-data php occ -V
The output of the above command should look something like:
Now, let’s say you have an app that’s not functioning properly (even causing you to be unable to access Nextcloud). First, list out all of your installed apps with the command:
sudo -u www-data php occ app:list
Locate the app in question from that list and then disable the offending app with the command:
sudo -u www-data php occ app:disable APPNAME
Where APPNAME is the name of the app to be disabled.
Finally, to list out all of the available occ commands, issue:
sudo -u www-data php occ list
And that is how you use the Nextcloud occ command to help you manage your Nextcloud installation from the command line interface. Make sure you understand how this works, on the off-chance you find yourself with a Nextcloud instance that doesn’t give you access to the GUI.
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.
Subscribe to the Cloud Insider Newsletter
This is your go-to resource for the latest news and tips on the following topics and more, XaaS, AWS, Microsoft Azure, DevOps, virtualization, the hybrid cloud, and cloud security. Delivered Mondays and Wednesdays