Skip to content

OCC Commands

Chen Asraf edited this page Nov 22, 2025 · 2 revisions

Manage the forum via command line.

Running OCC Commands

The way you run OCC commands depends on your Nextcloud installation method. Replace <command> with the actual forum command you want to run.

Direct Installation (Standard)

If Nextcloud is installed directly on your server:

cd /var/www/html/nextcloud
sudo -u www-data php occ <command>

Example:

sudo -u www-data php occ forum:repair-seeds

Docker Installation (AIO, Docker Compose)

Development Docker (docker-compose):

docker exec --user www-data -i nextcloud-nextcloud-1 php occ <command>

Nextcloud All-in-One (AIO):

docker exec --user www-data -it nextcloud-aio-nextcloud php occ <command>

Custom Docker container:

Find your container name first

docker ps | grep nextcloud

Then run the command

docker exec --user www-data -it <container-name> php occ <command>

Examples:

docker exec --user www-data -i nextcloud-nextcloud-1 php occ forum:rebuild-all-stats
docker exec --user www-data -it nextcloud-aio-nextcloud php occ forum:set-role alice admin

Snap Installation

If Nextcloud is installed via Snap:

sudo nextcloud.occ <command>

Example:

sudo nextcloud.occ forum:repair-seeds

Notes

  • Always run OCC commands as the web server user (www-data on most systems)
  • Use -i flag for non-interactive mode, -it for interactive mode
  • Adjust container names based on your Docker setup
  • Check your Nextcloud documentation if commands don't work as expected

General Administration

forum:repair-seeds

Initialize or repair forum data. Safe to run multiple times as it will skip data that already exists.

What it does:

  • Creates default roles (Admin, Moderator, User) if missing
  • Creates category headers if missing
  • Creates default categories if missing
  • Sets up category permissions for all roles
  • Creates default BBCodes if missing
  • Assigns user roles as needed
  • Creates welcome thread if missing

When to use:

  • After initial installation
  • To repair incomplete installations
  • After failed migrations
  • To restore missing default data

Statistics Management

forum:rebuild-all-stats

Rebuild all statistics including users, categories, threads, and posts.

What it does:

  • Rebuilds user statistics (post count, thread count, first/last post dates)
  • Rebuilds category statistics (thread count, post count)
  • Rebuilds thread statistics (post count, last post reference)

When to use:

  • When statistics appear incorrect or out of sync
  • After manual database modifications
  • After data import/migration

forum:rebuild-user-stats

Rebuild user statistics only.

What it does:

  • Recalculates post count for all users
  • Recalculates thread count for all users
  • Updates first and last post timestamps
  • Creates missing user stats records
  • Updates existing user stats records

Output: Shows number of users processed, created, and updated


forum:rebuild-thread-stats

Rebuild statistics for categories, threads, and posts.

What it does:

  • Recalculates thread count per category
  • Recalculates post count per category
  • Recalculates post count per thread
  • Updates last post references

Output: Shows number of categories and threads processed and updated

User Management

forum:set-role <username> <role>

Assign a forum role to a user.

Parameters:

  • username (required) - The Nextcloud username of the user
  • role (required) - Either a role ID (numeric) or role name (case-insensitive)

Examples:

Assign by role name

php occ forum:set-role alice admin
php occ forum:set-role bob moderator

Assign by role ID

php occ forum:set-role charlie 1

Notes:

  • Validates that the user exists in Nextcloud
  • Checks if role exists before assignment
  • Prevents duplicate role assignments
  • For multiple roles with same name, use numeric ID

Testing & Diagnostics

forum:test-notifier

Test the forum notification system.

What it does:

  • Instantiates the forum notifier
  • Creates a test notification
  • Attempts to prepare and format the notification
  • Displays notification details (subject, link, icon)

When to use:

  • To verify notification system is working
  • To debug notification issues
  • After notification configuration changes

Output: Shows notifier ID, name, and test notification details, or error messages if something fails

Quick Reference

Command Purpose Parameters
forum:repair-seeds Initialize/repair forum data None
forum:rebuild-all-stats Rebuild all statistics None
forum:rebuild-user-stats Rebuild user statistics only None
forum:rebuild-thread-stats Rebuild category/thread stats None
forum:set-role Assign role to user <username> <role>
forum:test-notifier Test notification system None

Tips

  • All rebuild commands are safe to run and won't damage data

  • Statistics commands can be run periodically via cron for maintenance

  • Use forum:repair-seeds as a first troubleshooting step for most issues

  • Check Nextcloud logs after running commands:

      tail -f /var/www/html/data/nextcloud.log
    

Clone this wiki locally