Console has to be executed with the user that owns the file config/config.php

hi im trying to install preview generator when i try to run this command sudo ./occ preview:generate-all -vvv im getting this error: Console has to be executed with the user that owns the file config/config.php
Current user id: 0
Owner id of config.php: 1005
Try adding ‘sudo -u #1005’ to the beginning of the command (without the single quotes)
If running with ‘docker exec’ try adding the option ‘-u 1005’ to the docker command (without the single quotes)

The title of your post actually gives you a hint. The occ command must be executed as the user that owns your Nextcloud installation. Usually this is the web server user, e.g. www-data, apache etc. The username and the exact command can vary, depending on which OS your Nextcloud is installed and which installation type you chose. So which operating system are you using and how did you install Nextcloud? (Docker, manual installation, Snap…)

In case you are using the official docker container, this might help: https://github.com/nextcloud/docker#using-the-nextcloud-command-line-interface

1 Like

With manual install you can make an alias to avoid needing sudo -u <user> every time. The alias below would be used if ./occ is located at /var/www/nextcloud/occ and the user that owns config/config.php is www-data. Adjust if either of those are different.

In ~/.bashrc

alias occ="sudo -u 'www-data' /var/www/nextcloud/occ"

After running source ~/.bashrc, occ status should run.