Cron Jobs for Nextcloud on Synology

I’ve just setup a Nextcloud instance on Synology running PHP7.3. Everything seems to be working fine except cron jobs.

Currently, I have the following command running in my Synology Task Scheduler:

curl —insecure https://localhost/nextcloud/cron.php

Unfortunately, the Nextcloud instance gives me “Some jobs haven’t been executed since 16 days ago. Please consider increasing the execution frequency”

Now, I’ve also tried running the following command in my Synology Task Scheduler in an attempt to resolve this:

su -s /bin/sh -c “/usr/local/bin/php73 -f /var/services/web/nextcloud/cron.php” http

This didn’t do much either, instead I received “The last Job Execution ran 12 minutes ago.”

Not really sure how to configure the Task Scheduler here to be able to run the /web/nextcloud/cron.php file from my Synology.

Any help would be greatly appreciated!

Thanks!

Nextcloud version : 19.0.1
Operating system and version : Linux 4.4.59+ aarch64
Apache or nginx version : Apache 7.3
PHP version : 7.3.16

UPDATE 20/0972020

With the intension of trying to solve this, I set it up to run cron.php via Webcron instead, I set this up via cron-jobs.org.

What’s interesting here is that the cron-job is successful, but Nextcloud is still saying “Some cron jobs haven’t been executed in xxx Days” - For reference, I’m attaching a print screen below:

Screenshot 2020-09-20 at 16.59.10

have you checked this post

Hey Vincent,

Thanks for that reply, unfortunately, I’ve already looked through that post. That post is what our current settings is based of, thats why I find it so strange that it’s not working.

Any other suggestions as to why the cronjob for nextcloud isn’t working on Synology would be super helpful!

Thanks!

I use this cron script in Scheduler (by root):
sudo -u http /var/packages/PHP7.3/target/usr/local/bin/php73 -c /usr/syno/etc/packages/WebStation/php_profile/11e7abb1-d10e-43cfb/conf.d/user_settings.ini -f /volume1/web/nextcloud/cron.php

You need to replace paths to php, profile and nextcloud folder

in response to SimyriK’s post on using the Task Scheduler in Synology:

Using your set up the scheduler failed.

I modified it to use the following which works without issue, for me. I use http for the web user.

Run as User: Root

Run Command:
User-defined script:

Put the following in the Script box.
sudo -u http php73 -f /volume1/web/nextcloud/cron.php

Thanks Belyache. That worked perfectly.

Hello,
I have tried to setup the NewsUpdater as suggested and keeps giving me errors.
Running Nextcloud 18.0.4 ON DSM 6.2.3
and the error I am getting is:
PHP Warning: PHP Startup: Unable to load dynamic library ‘mcrypt.so’ (tried: /usr/local/lib/php72/modules/mcrypt.so (/usr/local/lib/php72/modules/mcrypt.so: cannot open shared object file: No such file or directory), /usr/local/lib/php72/modules/mcrypt.so.so (/usr/local/lib/php72/modules/mcrypt.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘mysql.so’ (tried: /usr/local/lib/php72/modules/mysql.so (/usr/local/lib/php72/modules/mysql.so: cannot open shared object file: No such file or directory), /usr/local/lib/php72/modules/mysql.so.so (/usr/local/lib/php72/modules/mysql.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Console has to be executed with the user that owns the file config/config.php
Current user: http

Any pointers of what is happening? Aprt that it does not see 7.2 and I don’t want to upgrade the PHP 5.6. It has 7.2

Screenshot from 2021-01-01 15-32-42

Hi Belyache, sorry for my question that will look stupid to you, but root cannot access cron.php via docker.
So I tried to run the same task as you with:
docker container exec --user www-data -it nextcloud.domain php cron.php
Even if it works in ssh, it does not via the task scheduler (root).
Do you have an advice on how to trigger the php cron.php job within docker?

mateMat:

I don’t have any experience interacting with docker instances.

I tried a program about a year ago that used Docker, but I found it to be troublesome as I couldn’t really modify it from the original conifg. However, that could have been the specific program that was using Docker at that point.

I wish I could help more on this, best of luck.

Glenn

I found the error, the line of code should be:
docker container exec --user www-data -T nextcloud.domain php cron.php
Removing the t argument made it work.

Hi SimyriK, I have been struggling with this for some time now and can’t get the cron Job to work properly. I have installed NC 20.0.7 on my Synology Disk Station and am now trying to do the cleanup work from the installation. Pretty much the last thing to take care of is cron and that simply doesn’t work.
I found this setting: sudo -u http php73 /var/services/web/Nextcloud/cron.php

That didn’t work. Now I’ve been trying yours but can’t figure out how to adapt it to meet my folder/user structure. Can you help?

I tried that also (have the same problem) and it seemed to have worked once. NC gives me the warning “last task was carried out 12 minutes ago”. So I figure it must have worked once, right? Problem is now that it doesn’t seem to repeat every 5 mins as I set it up in the Syn task planner.

Any ideas?

First, you need to determine which version of PHP you are using - this can be found in WebStation in your DSM. Next, if you connect to synology via SSH, find the path of the executable file /var/packages/PHP_YOUR_VERSION/target/usr/local/bin/php_your_version:

simyrik@Diskstation:/$ /var/packages/PHP
PHP5.6/ PHP7.0/ PHP7.2/ PHP7.3/
simyrik@Diskstation:/$ /var/packages/PHP7.3/target/usr/local/bin/php
php73 php73-cgi php73-fpm phpdbg73
simyrik@Diskstation:/$ /var/packages/PHP7.3/target/usr/local/bin/php/php73

Next, go to the /usr/syno/etc/packages/WebStation/php_profile/ folder
and you look at all available profiles.

simyrik@Diskstation:/$ cd /usr/syno/etc/packages/WebStation/php_profile/
simyrik@Diskstation:/usr/syno/etc/packages/WebStation/php_profile$ ls -la
total 20
drwxr-xr-x 5 root root 4096 May 8 2020 .
drwxr-xr-x 5 root root 4096 Oct 7 01:03 …
drwxr-xr-x 3 root root 4096 Feb 17 05:06 11e7abb1-d10e-43cf-aa64-cbb43fddc61b
drwxr-xr-x 3 root root 4096 Feb 17 05:06 844257d5-dd27-4885-8fd8-96cf320e39ac
drwxr-xr-x 3 root root 4096 Feb 17 05:06 9f1e642a-0d20-4664-8934-c51d34f609de

You can try to determine the used profile in several ways

  1. According to php version:

simyrik@Diskstation:/usr/syno/etc/packages/WebStation/php_profile$ find */fpm.conf
-type f -print -exec cat {} ; | grep ‘conf|pid’
11e7abb1-d10e-43cf-aa64-cbb43fddc61b/fpm.conf
pid = /run/php-fpm/php73-11e7abb1-d10e-43cf-aa64-cbb43fddc61b.pid
844257d5-dd27-4885-8fd8-96cf320e39ac/fpm.conf
pid = /run/php-fpm/php56-844257d5-dd27-4885-8fd8-96cf320e39ac.pid
9f1e642a-0d20-4664-8934-c51d34f609de/fpm.conf
pid = /run/php-fpm/php70-9f1e642a-0d20-4664-8934-c51d34f609de.pid

  1. If vhost is used, you can also find ‘nexclod’:

simyrik@Diskstation:/usr/syno/etc/packages/WebStation/php_profile$ find */conf.d/webstation_vhost.ini -type f -print -exec cat {} ; | grep ‘nextcloud|ini’

11e7abb1-d10e-43cf-aa64-cbb43fddc61b/conf.d/webstation_vhost.ini
open_basedir = /volume1/web/owncloud:/tmp:/var/services/tmp:/var/services/web:/var/services/homes:/dev/urandom:/volume1/owncloud:/volume1/nextcloud:/volume1/calibre:/proc/meminfo

And then you put it all together (highlighted in bold what needs to be replaced with your data):

sudo -u http /var/packages/PHP7.3/target/usr/local/bin/php73 -c /usr/syno/etc/packages/WebStation/php_profile/11e7abb1-d10e-43cfb/conf.d/user_settings.ini -f /volume1/web/nextcloud/cron.php

Hi SimyriK,

Thank you very much. I was able to sort it out, it was a user/usage rights problem that I was able to fix.

Thank you very much!

Cheers
DM

sudo -u http /var/packages/PHP7.3/target/usr/local/bin/php73 -c /usr/syno/etc/packages/WebStation/php_profile/4ef993c6-20f5-4b6a-91ae-148eaec4805a/conf.d/user_settings.ini -f /volume1/web/Nextcloud/cron.php

Can do this in console and works
but i does not work in task scheduler

I struggled with that too. I got it working. This is my command:

sudo -u http /usr/local/bin/php74 -c /var/packages/WebStation/etc/php_profile/9f1e642a-0d20-4664-8934-c51d34f609de/conf.d/user_settings.ini -f /volume1/web/nextcloud/cron.php

These are my task scheduler settings:

Run on the following days: Daily
First run time: 00:00
Frequency: Every 5 minutes
Last run time: 23:55

Once I’d set up this schedule it worked perfectly.

Indeed Thats works
Minor bug i think on the timing thingie

1 Like

Hi,

Can’t get it to work here.
Task is ending in error because it waits for the password :

This is my script :
sudo -u http /usr/local/bin/php74 -c /var/packages/WebStation/etc/php_profile/c955c07d-aa67-4013-bcda-4189fb9a1f34/conf.d/user_settings.ini -f /volume1/web/nextcloud/cron.php

Error :

sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
sudo: a password is required

What am I doing wrong ?

Hi,

Is that work on DSM 7 or only with DSM 6.2.3 ?

Regards,

This code is giving me error on my ds220+. What can I do?

Standardausgabe/Fehler:
OCP\HintException: [0]: Memcache \OC\Memcache\APCu not available for
local cache (Is the matching PHP module installed and enabled?)