The 9 most important Nextcloud OCC commands for the console

To use Nextcloud optimally, it can be helpful to know some OCC commands that can be executed via the console. This can be useful, for example, for Nextcloud troubleshooting, scripts, updates, etc.

OCC stands for OwnCloud Console and is a tool that enables various administrative tasks. In this article, we present some of the most important OCC commands that can be useful for experienced Nextcloud users.

Using OCC


OCC is a PHP script found in the Nextcloud directory under the name occ. It can be called with the command php occ, where you must be in the Nextcloud directory (/var/www/nextcloud). To use OCC, you must either be the web server user (e.g., www-data) or specify the option –user with the corresponding username. Additionally, you must have sufficient permissions to perform the desired actions.

OCC offers a range of functions divided into different categories. To see a list of all available functions, you can use the command sudo -u www-data php occ list. To get more information about a specific function, you can use the command sudo -u www-data php occ help .

The Most Important OCC Commands


Here are some of the most important OCC commands that we recommend for experienced Nextcloud users:

  1. php occ maintenance:mode
    This command enables or disables the maintenance mode of Nextcloud. In maintenance mode, no users can access Nextcloud except the administrator. This is useful when you want to make changes to the configuration or code of Nextcloud without disturbing other users.

To enable maintenance mode, use the command

sudo -u www-data php occ maintenance:mode --on

To disable it, use the command

sudo -u www-data php occ maintenance:mode --off
  1. php occ upgrade
    This command upgrades Nextcloud to the latest version. This should always be done when a new version of Nextcloud is available to benefit from the latest features and security updates.

To perform an upgrade, you must first enable maintenance mode (see above) and then execute the command sudo -u www-data php occ upgrade. The command checks if a new version is available and then performs the upgrade. After the upgrade, you should disable maintenance mode (see above).

  1. php occ app:command
    This command allows you to manage apps in Nextcloud. Apps are extensions that provide additional features or customizations for Nextcloud. There are many apps developed by the Nextcloud community available in the Nextcloud App Store.

To see a list of all installed apps, use the command sudo -u www-data phpocc app:list To enable or disable a specific app, use the command sudo -u www-data php occ app:enable app-id or sudo -u www-data php occ app:disable app-id. To install or update an app, use the command sudo -u www-data php occ app:install app-id or sudo -u www-data php occ app:update app-id.

  1. php occ files:scan user_id
    This command scans the files of one or more users and updates the database with the latest information. This is useful if you have added or changed files outside of Nextcloud, for example via FTP or SSH.

To scan the files of a specific user, use the command sudo -u www-data php occ files:scan user_id . To scan the files of all users, use the command sudo -u www-data php occ files:scan –all.

  1. php occ encryption
    This command allows you to manage encryption in Nextcloud. Encryption protects files and data from unauthorized access by encoding them with a secret key. Nextcloud supports both server-side and client-side encryption.

To enable or disable server-side encryption, use the command sudo -u www-data php occ encryption:enable or sudo -u www-data php occ encryption:disable. To enable or disable client-side encryption, use the command php occ encryption:enable-master-key or php occ encryption:disable-master-key.

  1. php occ user
    This command allows you to manage users in Nextcloud. Users are the people who access Nextcloud and can store and share files and data. Nextcloud allows you to create users manually or import them from external sources like LDAP or SAML.

To create a new user, use the command sudo -u www-data php occ user:add . To delete an existing user, use the command sudo -u www-data php occ user:delete . To assign or remove a user from a group, use the command sudo -u www-data php occ user:add-group or sudo -u www-data php occ user:remove-group.

  1. php occ config
    This command allows you to manage the configuration of Nextcloud. The configuration contains various settings that affect the behavior and appearance of Nextcloud. The configuration is stored in a file named config.php, which can be found in the Nextcloud directory under the config folder.

To see a list of all configuration options, use the command sudo -u www-data php occ config:list. To change or add a specific configuration option, use the command sudo -u www-data php occ config:system:set –value=. To delete a specific configuration option, use the command sudo -u www-data php occ config:system:delete .

  1. sudo -u www-data php occ db
    This command allows you to manage the database of Nextcloud. The database stores all information about users, files, apps, and other data of Nextcloud. Nextcloud supports various database types like MySQL, PostgreSQL, SQLite, or Oracle.

To see a list of all database commands, use the command sudo -u www-data php occ db. To convert or migrate the database, use the command sudo -u www-data php occ db:convert-type . To repair or optimize the database, use the command sudo -u www-data php occ db:repair or sudo -u www-data php occ db:optimize.

  1. sudo -u www-data php occ log
    This command allows you to manage the log file of Nextcloud. The log file contains all events and error messages that occur in Nextcloud. The log file is useful for troubleshooting and monitoring Nextcloud. The log file is stored in a file named nextcloud.log, which can be found in the Nextcloud directory under the data folder.

To see a list of all log commands, use the command sudo -u www-data php occ log. To change or specify the log level, use the command php occ log:manage –level= or sudo -u www-data php occ log:manage –level= –output=. To clear or display the log, use the command sudo -u www-data php occ log:clear or sudo -u www-data php occ log:tail.

These were some of the most important OCC commands you should know for managing your Nextcloud instance. With these commands, you can perform various administrative tasks, such as enabling or disabling apps, updating or repairing the database, changing or displaying the configuration, and much more.

Of course, there are many more OCC commands you can discover by consulting the OCC help or the Nextcloud documentation.

We are happy to support you with your Nextcloud troubleshooting or your Nextcloud project. Feel free to contact us without obligation.