Can't Run Background Jobs with System Cron

Nextcloud version: 21.0.2
Operating system and version: Ubuntu 20.04
Apache or nginx version: Apache/2.4.41
PHP version: 7.4

The issue you are facing:
When I set background jobs to cron under basic settings and add the line

*/5 * * * * php -f /var/www/nextcloud/cron.php

to crontab using sudo -u www-data crontab -e it does not update the “Last job ran…” notification on the settings menu. When I run cron.php from the cli it runs just fine (I had to set the log_level to 1 to get this to run otherwise it would just hang indefinitely) and it updates the “Last job ran…” notification. If I check journalctl | grep CRON I can see that the cron job is run every 5 minutes as expected, but the notification does not update. After looking through the forums I tried updating the memory_limit under /etc/php/7.4/cli/php.ini as I only had it set in …/apache2/php.ini, but this did not work. This problem has only become apparent after updating to NC 21.0.2 from NC 20.0.8 however I cannot verify whether it was working before the update as I was just using AJAX then. Also, it may be of note that I had to add apc.enable_cli=1 to /etc/php/7.4/mods-available/apcu.ini as well as have ‘memcache.local’ => ‘\OC\Memcache\APCu’, in $NEXTCLOUD/config/config.php in order to get things like occ to run after updating.

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

Steps to replicate it:

  1. Change to system cron
  2. Add relevant cronjob to crontab
  3. Notice that last background job notification does not update

I will provide any relevant logs if necessary, but the only relevant thing the logs appear to show is occasionally some logging from cron.php if I run on cli.

1 Like

Same here. I tried to switch to webcron and AJAX, but it also doesn’t run tasks. Logs don’t contain anything related to cron jobs.


I probably have a solution.

When i tried to run the occ command for some reason, i got an error message about \OC\Memcache\APCu, and some dependencies not being installed. It turned out that i had to enable APC in the CLI, by setting apc.enable_cli=1 in my PHP configuration.

After that, both cron jobs and OCC work just fine.

Hope that helps!

I already have APC set and it doesn’t work, but thanks anyways.

That’s what i thought, too, as the NC web worked just fine. What i had to enable is the CLI support of APC. Sorry if that was clear already.