Not able to execute occ command on Synology

  1. Install nextcloud on Webstation/Synology
  2. Try to execute ssh command
    sudo -u http php /volume1/web/nextcloud/occ status

Actual behaviour

When executing the occ status command or any other occ command, i am getting the following error message:

An unhandled exception has been thrown:
exception ‘Exception’ with message ‘Environment not properly prepared.’ in /volume1/web/nextcloud/lib/private/Console/Application.php:145
Stack trace:
#0 /volume1/web/nextcloud/console.php(91): OC\Console\Application-loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 /volume1/web/nextcloud/occ(11): require_once(’/volume1/web/ne…’)

With phpinfo i found out that my PHP user is http. Complete nextcloud folder is owned by http user.b

Server configuration

Operating system: Synology DSM newest version

Web server: Apache 2

Database: Sqlite3 12.0.0.29

PHP version: php5.6.11

Nextcloud version: nextcloud 12.0.0

Updated from an older Nextcloud/ownCloud or fresh install: fresh install

Hope you can help me with the error message

Does Nextcloud web ui work on the other hand?

In case please show your config.php and webserver configs.

I got it…Instead of using php you have to use php56 command on synology diskstations. Thanks anyways.

1 Like

Good to know :slight_smile:

In recent versions, Nextcloud does not support php 5.6 any more. Using the above command with php70 instaed triggers a long error message, basically due to some modules (namely database connection) are missing. I have activated all necessary modules in the Web Station PHP configuration, but that configuration is apparently not used if php is called via the command line.
Any idea how to get the command line running with Nextcloud 15?

Found an answer myself at https://blog.viking-studios.net/synology-php-7-cli-fehlerfrei-nextcloud-und-php-7/. For reference, here are the steps in English:

  1. The php configs are located at /var/packages/WebStation/etc/php_profile/xxxx/conf.d/, where xxxx are some random letters. Find the right folder with your configuration by comparing the content of the file user_settings.ini with the choice of modules in WebStation.
  2. Create a new file with the following content (replace xxxx with your random letters!):

#!/bin/bash
PHP_INI_SCAN_DIR=.:/usr/local/etc/php70/:/var/packages/WebStation/etc/php_profile/xxxx/conf.d/
export PHP_INI_SCAN_DIR
php70 $*

  1. Make the script executable (chmod +x …)

Now you can call occ (or other command line php calls) by using the script (here I use -i to get the phpinfo() output):

sudo -u http /path/to/script -i

@d-tamm
If you install the php 7.2 package from package center you can use the command again by typing php72 occ or php70 occ, had the same problem and workaround

No, does not work for me. I get a long error stack message, slightly different for php 7.0 and php 7.2.

php70:

# sudo -u http php70 occ
An unhandled exception has been thrown:
Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occured in driver: could not find driver in /volume1/web/nextcloud/lib/private/DB/Connection.php:64
Stack trace:

php72:

# sudo -u http php72 occ
An unhandled exception has been thrown:
Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [2002] No such file or directory in /volume1/web/nextcloud/lib/private/DB/Connection.php:64
Stack trace:

Also, the workaround described above (shell script) does not work for me with php72. php70 works fine.

Anyone who has managed to get php 7.2 running with occ? I cannot run 7.0 any more because it always will disable apps requiring >=7.1.

I have NC 15.0.7 running with PHP 7.2 on Synology DS418.
Problems are typically caused by php settings and (missing) modules.
I have a writeup how I did it, it may be helpful.

https://www.squirrel.nl/pub/xfer/uploads/3CGiHtQ_FsmxxD3sr3Zmwt2Q.txt