Quick Reference

Cheatsheets

Practical command references for Linux, networking, servers, containers, databases, and more.

Cheatsheet#nextcloud-cheatsheet

Nextcloud Cheatsheet

Nextcloud is an open-source, self-hosted file share and collaboration platform. Administration is heavily reliant on the occ (ownCloud Console) command-line tool.

Installation Basics

Nextcloud is typically installed on a LAMP/LEMP stack (Linux, Apache/Nginx, MySQL/MariaDB, PHP).

# Common prerequisites (Debian/Ubuntu example)
sudo apt install apache2 mariadb-server libapache2-mod-php
sudo apt install php-gd php-mysql php-curl php-mbstring php-intl php-gmp php-bcmath php-xml php-imagick php-zip
 
# Download and extract
wget https://download.nextcloud.com/server/releases/latest.tar.bz2
tar -xjvf latest.tar.bz2
sudo cp -r nextcloud /var/www/
sudo chown -R www-data:www-data /var/www/nextcloud

Basic occ Execution

Important: The occ command must be run as the web server user (usually www-data on Debian/Ubuntu or apache on RHEL/CentOS).

Navigate to your Nextcloud directory (e.g., /var/www/nextcloud) first, or provide the full path.

# Ubuntu/Debian
sudo -u www-data php /var/www/nextcloud/occ
 
# RHEL/CentOS
sudo -u apache php /var/www/html/nextcloud/occ

User Management

# List all users
sudo -u www-data php occ user:list
 
# Add a new user
sudo -u www-data php occ user:add username
 
# Reset a user's password
sudo -u www-data php occ user:resetpassword username
 
# Disable/Enable a user
sudo -u www-data php occ user:disable username
sudo -u www-data php occ user:enable username
 
# Delete a user
sudo -u www-data php occ user:delete username

App Management

# List all apps (enabled and disabled)
sudo -u www-data php occ app:list
 
# Enable an app
sudo -u www-data php occ app:enable app_id
 
# Disable an app
sudo -u www-data php occ app:disable app_id
 
# Update all apps
sudo -u www-data php occ app:update --all

Maintenance Mode and Upgrades

Enable maintenance mode before manual backups or upgrades.

# Enable maintenance mode
sudo -u www-data php occ maintenance:mode --on
 
# Disable maintenance mode
sudo -u www-data php occ maintenance:mode --off
 
# Run the database upgrade routine (after updating core files)
sudo -u www-data php occ upgrade

File Scanning and Syncing

If files are added directly to the filesystem (bypassing the web interface or sync client), Nextcloud won't see them until you scan the files.

# Scan files for all users
sudo -u www-data php occ files:scan --all
 
# Scan files for a specific user
sudo -u www-data php occ files:scan username
 
# Scan a specific path
sudo -u www-data php occ files:scan --path="/username/files/Photos"

Background Jobs (Cron)

Nextcloud requires background jobs to process tasks (like cleaning up old files, sending notifications, etc.). The most reliable method is system cron.

Add this to the web server user's crontab (sudo -u www-data crontab -e):

# Run the Nextcloud cron script every 5 minutes
*/5 * * * * php -f /var/www/nextcloud/cron.php

You must also configure Nextcloud to use "Cron" in the admin settings (Settings > Basic settings > Background jobs).

Security and Setup Warnings

After installation, the admin panel often shows warnings. Common fixes via occ:

# Add missing database indices
sudo -u www-data php occ db:add-missing-indices
 
# Convert database columns to big int
sudo -u www-data php occ db:convert-filecache-bigint