Jack Wallen shows you how to administer your Nextcloud installation from the command line.
<figure class="image pull-none image-large"><a href="https://publifex.com/cloud/wp-content/uploads/2020/10/How-to-add-a-social-component-to-your-Nextcloud-instance.jpg" target="_blank" data-component="modalEnlargeImage" data-headline="<p></p>" data-credit="Image: Jack Wallen" rel="noopener noreferrer nofollow"><span class="img aspect-set " style="padding-bottom: 78%"><img src="https://publifex.com/cloud/wp-content/uploads/2020/10/How-to-add-a-social-component-to-your-Nextcloud-instance.jpg" class="" alt="nextcloudhero.jpg" width="770"/></span></a><figcaption><p> Image: Jack Wallen </p></figcaption></figure>
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
<p>Or:</p><pre class="code">sudo -u apache COMMAND</pre> <p>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
<p>We have to run it like so: </p><pre class="code">sudo -u apache php occ</pre> <p>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 <em>occ</em> 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
<p>The output of the above command should look something like: </p><pre class="code">Nextcloud 20.0-4</pre> <p>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: </p><pre class="code">sudo -u www-data php occ app:list</pre> <p>Locate the app in question from that list and then disable the offending app with the command: </p><pre class="code">sudo -u www-data php occ app:disable APPNAME</pre> <p>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
<p>And that is how you use the Nextcloud <em>occ</em> 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.
<h2> Also see </h2> </div>