How to execute an occ command using scheduled tasks on Plesk

Nextcloud version (eg, 20.0.5): 23.0.2
Operating system and version (eg, Ubuntu 20.04): Linux 3.10.0-1160.53.1.el7.x86_64
Apache or nginx version (eg, Apache 2.4.25): Apache (cgi-fcgi)
PHP version (eg, 7.4): 8.0.15

How can occ commands be executed using scheduled tasks in Plesk?

In this post Missing indexes after upgrade to NC18, db:add-missing-indices failing it was mentioned that they could be done using cron jobs.

In Plesk there are three types of scheduled tasks:
a) Run a command
b) Fetch a URL
c) Run a PHP script

See https://docs.plesk.com/en-US/obsidian/reseller-guide/website-management/scheduling-tasks.70617/

Which one is the correct type and what command should be entered if Nextcloud is in the subfolder cloud.domain.com of the root folder?

I tried option a) and php ./occ db:add-missing-indices or php occ db:add-missing-indices or php ./cloud.domain.com/occ db:add-missing-indices but it returned “Could not open input file: …”.

I’m not really savvy with occ and cron jobs so am grateful for your advice.

Use the first one “Run a command” you can see in this picuture.

Instead of touch /tmp/test.txt insert:

sudo -u www-data [....]

And then press Run Now.
Not tested. I have got no Plesk.

That make no really sense. Only after Nextcloud upgrade look in the messages and then execute it only once.

Thank you for your help!

First I tried your suggestion and it didn’t work with Plesk. With support from the hosting company we managed to find the solution, applicable to Plesk Obsidian 18.0.x:

  1. Task type: Run a command
  2. Command: php /path/to/nextcloud/directory/occ db:add-missing-indices
    (replace “/path/to/nextcloud/directory/” by the actual path)
  3. Leave the other settings as they are.
  4. Click “Run now”.

Thanks again and have a good week!

1 Like