Nextcloud Occ Command
In this tutorial, you'll learn about Nextcloud occ Command Fails. We cover key concepts, practical examples, and best practices.
Hook
You SSH into your Nextcloud server to run occ maintenance:mode --on and get "sudo: occ: command not found." You are in the Nextcloud directory. The file exists. But the command does not run.
The Wrong Way
Running php occ as root without switching to the web server user creates files owned by root, causing permission errors in the Nextcloud web UI.
# BAD: Running occ as root
sudo php /var/www/nextcloud/occ maintenance:mode --on
Maintenance mode enabled
Nextcloud web UI: "Can't write to config"
Config.php owned by root — web server cannot write
Running occ as root writes cache files and updates config.php with root ownership, breaking the web interface.
The Right Way
Always run occ as the web server user.
# Find the correct user
grep -r "^User\|^Group" /etc/apache2/envvars
# Or for Nginx:
ps aux | grep nginx | head -1
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
# Run occ as www-data
sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --on
Nextcloud is currently in maintenance mode
Config.php permissions: www-data ✓
If php is not in the www-data PATH, use the full path:
sudo -u www-data /usr/bin/php8.3 /var/www/nextcloud/occ maintenance:mode --off
For convenience, create an alias:
alias ncc='sudo -u www-data php /var/www/nextcloud/occ'
ncc status
Prevention
- Always prefix
occcommands withsudo -u www-data(or your web server user). - Never run occ as root — it breaks file permissions.
- Set up a shell alias (
ncc) to avoid typing the full wrapper each time. - If you use Docker, exec into the container as the
www-datauser. - Keep
phpin the system PATH for the web server user.
Advanced Troubleshooting
Check the Logs
Most TOOL errors are logged to stdout or a dedicated log file. Check your logs first:
# Check system logs
journalctl -u tool --since "1 hour ago"
# Or check the application log
tail -50 ~/.tool/logs/error.log
Test with a Minimal Example
Create the simplest possible tool configuration to verify the base setup works:
tool --version
tool --help
If the minimal test passes, add configuration options one at a time until you find the breaking change.
Common Configuration Mistakes
- Using the wrong file path or URL in configuration
- Forgetting to restart TOOL after changing config files
- Mixing tabs and spaces in YAML configuration files
- Setting incorrect permissions on configuration directories
When to Reinstall
If none of the above resolves the issue, consider a clean reinstall:
# Backup your configuration
cp -r ~/.tool ~/.tool.bak
# Remove and reinstall
# Follow the official TOOL installation guide
This ensures you start from a known good state and can isolate the issue.
Common Mistakes with occ command
- Using
foldlinstead offoldl'causing stack overflow on large lists - Forgetting
deriving (Show, Eq)on custom data types needed for debugging - Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
These mistakes appear frequently in real-world NEXTCLOUD code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
DodaTech — command your Nextcloud server with confidence.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro