OCC command just gives permission error

My YunoHost server

Hardware: VPS bought online
YunoHost version: 11.2.11.2
I have access to my server : Through SSH | through the webadmin
Are you in a special context or did you perform some particular tweaking on your YunoHost instance ? : no
If yes, please explain:
If your request is related to an app, specify its name and version: Nextcloud 28.0.4~ynh2

Description of my issue

I am trying to run a Nextcloud occ command with:
sudo -u nextcloud php8.1 --define apc.enable_cli=1 /var/www/nextcloud/occ

(I also tried php8.2 and 7.4) This used to work for me, but now I get the following error message:

Sorry, user MYUSERNAME is not allowed to execute '/usr/bin/php8.1 --define apc.enable_cli=1 /var/www/nextcloud/occ' as nextcloud on SUB.MYDOMAIN.TLD.

My user is an admin, but if I try and use su, nome of my passwords seem to work. It will let me do sudo echo “hello”, but I get the same permission error using sudo -u MYUSERNAME echo “Hello”. :person_shrugging:

So, how can I execute occ now?

You need to switch to root user first by issuing sudo su, then run sudo -u and so on.

Alternatively, given nextcloud switched to packaging v2 it should be possible to activate interactive shell with sudo yunohost app shell nextcloud and issue commands an appropriate user from an appropriate directory with an appropriate PHP version (?) already.

1 Like

Yes, and even with the required --define apc.enable_cli=1 flag. :wink: Just type php occ ...

2 Likes

Hummm, I tried this

sudo yunohost app shell nextcloud

all right I am then connected as nextcloud user in the shell, but if I do

php occ list

php occ list
Error in argument 1, char 1: no argument for option -
Usage: php [options] [-f] <file> [--] [args...]
   php [options] -r <code> [--] [args...]
   php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]
   php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]
   php [options] -S <addr>:<port> [-t docroot] [router]
   php [options] -- [args...]
   php [options] -a

  -a               Run as interactive shell (requires readline extension)
  -c <path>|<file> Look for php.ini file in this directory
  -n               No configuration (ini) files will be used
  -d foo[=bar]     Define INI entry foo with value 'bar'
  -e               Generate extended information for debugger/profiler
  -f <file>        Parse and execute <file>.
  -h               This help
  -i               PHP information
  -l               Syntax check only (lint)
  -m               Show compiled in modules
  -r <code>        Run PHP <code> without using script tags <?..?>
  -B <begin_code>  Run PHP <begin_code> before processing input lines
  -R <code>        Run PHP <code> for every input line
  -F <file>        Parse and execute <file> for every input line
  -E <end_code>    Run PHP <end_code> after processing all input lines
  -H               Hide any passed arguments from external tools.
  -S <addr>:<port> Run with built-in web server.
  -t <docroot>     Specify document root <docroot> for built-in web server.
  -s               Output HTML syntax highlighted source.
  -v               Version number
  -w               Output source with stripped comments and whitespace.
  -z <file>        Load Zend extension <file>.

  args...          Arguments passed to script. Use -- args when first argument
                   starts with - or script is read from stdin

  --ini            Show configuration file names

  --rf <name>      Show information about function <name>.
  --rc <name>      Show information about class <name>.
  --re <name>      Show information about extension <name>.
  --rz <name>      Show information about Zend extension <name>.
  --ri <name>      Show configuration for extension <name>.

bash: apc.enable_cli=1: command not found

even adding --define apc.enable_cli=1 it did not works…

So only this works for me

sudo -u nextcloud php8.2 --define apc.enable_cli=1 /var/www/nextcloud/occ 

After that

php8.2 --define apc.enable_cli=1 occ app:list

Ooops that means my nice code for app shell is broken. Sorry about that, I will work on fixing this over the weekend. :sweat_smile:

3 Likes

That was the key I needed to get this working. THANK YOU!

@tituspijean I never realized this existed! So cool, if it’s what it sounds like. Does this mean that after it’s fixed it would be possible to just do:

sudo yunohost app shell nextcloud app:list
…or similar?

sudo yunohost app shell nextcloud should enter an interactive shell where issuing occ app:list should just work out of the box.

1 Like

@rodinux I actually could not replicate your issue. I’m on YunoHost 11.2.11.2 and Nextcloud 28.0.4~ynh1.

You can do as orhtej2 proposed, sudo yunohost app shell nextcloud then whatever command you want to run. You should though call occ with php: php occ ..., as occ does not have the execute permission by default and directly calling it would not have the apc.enable thingy included.

If you want to directly run a command: sudo yunohost app shell nextcloud <<< "php occ app:list", though I was not able to silence all the helpers loading at the beginning yet, they are a bit too verbose to my taste.

2 Likes