Occ command doesn't work

Nextcloud version : 15.0.12
Operating system and version : CentOS Linux 7.5.1804 (Core)
Apache or nginx version : Apache 2.4.6
PHP version : 7.3.10 as FPM application served by Apache

Hello,

The issue you are facing:

Is this the first time you’ve seen this error? (Y/N): Y

I’ve upgraded my Nexcloud instance from 14.x to 15.0.12. I get some warning about missing index, and columns not being converted in big int. I’ve used the occ command as was mentionned in the warning, and I get that (what I show you is for missing indexes, but I get the same problem for all occ commands) :

sudo -u apache php ./occ db:add-missing-indices
PHP Parse error: syntax error, unexpected ‘class’ (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or ‘{’ or ‘$’ in /var/www/vhosts/madonie.org/subdomains/nuage/console.php on line 93

I do the upgrade manually, since I always get an error message at the backup step of the web upgrade.

I guess I have to solve this problem before upgrading to 16.x, and eventually 17.x after.

Thank you

I’ve run into something like this when the PHP cli version is out of date. What PHP version are you running on the command line?
php -v

WHERE do you do that? in which directory? - you ought to do that in your nextcloud-directory.

have you installed NC as a docker or snap?

good luck

I’m doing that in the Nextcloud folder.
No Docker. I just download the zip archive of Nextcloud and upload its content in the Nextcloud folder. I don’t know what you mean by snap.

All the information on my server are in my message :slight_smile:

did you try sudo php occ db:add-missing-indices as well? is apache the webuser?

I don’t think your message includes the cli version of PHP. There is a difference between the PHP Apache uses and the PHP you run in the terminal. Your issue is most likely due to a problem with the CLI version of PHP that you are using. Did you try running php -v to see what version that is?

Either way, the error message you posted is a syntax error which can only be one of two things: the code is broken or the code is incompatible with the version of PHP used to run it.

3 Likes

Thank you for your explanation. You’re right, php client was an old version :

php -v
PHP 5.4.16 (cli) (built: Oct 30 2018 19:30:51)

Trying to know why, I’ve learnt two things :

  1. I’m using Plesk, and it installs several version of PHP in its own directory :

ls /opt/plesk/php/
5.6 7.0 7.1 7.2 7.3

So it was not the /usr/bin/php I should have used, but the one in the bin directory of the PHP version I use. In my case :

/opt/plesk/php/7.3/bin/php

  1. Using PHP as FPM application served by Apache, I haven’t changed the ownership and the permissions of the files and folders of Nextcloud. So it was not Apache user I had to use, but my username in sudo. For example :

sudo -u my_usename /opt/plesk/php/7.3/bin/php ./occ db:convert-filecache-bigint

This way everything has worked fine :slight_smile:

1 Like

Nice! I’m glad you got it working.

But I don’t think it’s a good idea to run the nextcloud with your username. Give it a dedicated username like www-nextcloud, the nextcloud folder and the data folder should be owned by that user. This is for security.

In fact, it’s not the username I use to connect with ssh to my server. It’s the ftp user for the domain nextcloud is part of. Do you mean it would be more secure to have a ftp user just for Nextcloud ?

No I mean a total separate user that is only used for nextcloud. I do not use ftp at all, because it is insecure too. You can do all configuration via ssh and use sudo to write to the nextcloud directories.

In order not to multiply topics:

Nextcloud install from here: https://www.qnapclub.eu/en/qpkg/348 (plus /opt/Qapache/bin/php -v
PHP 7.2.18 (cli) (built: May 8 2019 11:42:07) ( ZTS )
Copyright © 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright © 1998-2018 Zend Technologies
with Xdebug v2.6.1, Copyright © 2002-2018, by Derick Rethans)

According to the recommendations, I can change the type of database (default SQLlite), create the required indexes … But none of the operations does not work

for example:
[~] # /opt/NextCloud/nextcloud/occ db:convert-type
env: php: No such file or directory

What to do? Where and what to change? (To provide the necessary information is not a problem)

In LINUX I almost beginner :frowning:

Do this:
cd /opt/NextCloud/nextcloud

ls -l

Now you seed the owner and group of the user that runs the web server. On a Debian/Ubuntu system that would be www-data.

You need to run the occ command as that user. Like:

sudo -u www-data php occ db:convert-type

Does this work for you? Also read this:
https://docs.nextcloud.com/server/18/admin_manual/configuration_database/db_conversion.html

[~] # cd /opt/NextCloud/nextcloud
[/opt/NextCloud/nextcloud] # ls -l
drwxrwxr-x 33 admin administ 4096 Mar 28 13:49 3rdparty/
-rwxrwxr-x 1 admin administ 15752 Mar 11 17:52 AUTHORS*
-rwxrwxr-x 1 admin administ 34520 Mar 11 17:52 COPYING*
drwxrwxr-x 44 admin administ 4096 Apr 8 10:22 apps/
drwxrwxr-x 2 admin administ 4096 Apr 9 19:37 config/
-rwxrwxr-x 1 admin administ 3910 Mar 11 17:52 console.php*
drwxrwxr-x 23 admin administ 4096 Mar 28 13:49 core/
-rwxrwxr-x 1 admin administ 5048 Mar 11 17:52 cron.php*
drwxrwx— 6 admin administ 4096 Apr 10 18:42 data/
-rwxrwxr-x 1 admin administ 156 Mar 11 17:52 index.html*
-rwxrwxr-x 1 admin administ 2976 Mar 11 17:52 index.php*
drwxrwxr-x 6 admin administ 4096 Mar 28 13:49 lib/
-rwxrwxr-x 1 admin administ 283 Mar 11 17:52 occ*
drwxrwxr-x 2 admin administ 4096 Mar 28 13:49 ocm-provider/
drwxrwxr-x 2 admin administ 4096 Mar 28 13:49 ocs/
drwxrwxr-x 2 admin administ 4096 Mar 28 13:49 ocs-provider/
-rwxrwxr-x 1 admin administ 3056 Mar 11 17:52 public.php*
-rwxrwxr-x 1 admin administ 5235 Mar 11 17:52 remote.php*
drwxrwxr-x 4 admin administ 4096 Mar 28 13:49 resources/
-rwxrwxr-x 1 admin administ 26 Mar 11 17:52 robots.txt*
-rwxrwxr-x 1 admin administ 2381 Mar 11 17:52 status.php*
drwxrwxr-x 3 admin administ 4096 Mar 28 13:49 themes/
drwxrwxr-x 2 admin administ 4096 Mar 28 13:49 updater/
-rwxrwxr-x 1 admin administ 362 Mar 18 16:15 version.php*
[/opt/NextCloud/nextcloud] # sudo -u www-data php occ db:convert-type
sudo: unknown user: www-data
sudo: unable to initialize policy plugin
[/opt/NextCloud/nextcloud] #

Obviously the directory is owned by the admin user. Are you sure that this is the owner running the web server? If yes, the command would be

sudo -u admin php occ db:convert-type

But I suspect this is not the case. You must check out your system, we cannot help you if you don’t provide important information.

Btw, are you hijacking the thread of another user? You should open your own thread to avoid confusion.

I have ssh session, login under administrator
I clarify once again - it is NAS QNAP ts-231p - and it has its own operating system.

[/opt/NextCloud/nextcloud] # sudo -u admin php occ db:convert-type
sudo: php: command not found