Fixing a strange Nextcloud CRON Not Running Issue

I’ve been having a weird issue with one of my Nextcloud instances where it indicates that CRON isn’t running, or more specifically “Something seems wrong.” But when I look at the CRON log, it looks like all is good, but it actually wasn’t because Nextcloud wasn’t surfacing an error, just failing silently. Which every IT person knows, is the worst way to fail. This is how I figured out the problem, and how I fixed it.

This instance of Nextcloud is running on Unbuntu, so the first place to check if CRON is running, and what it’s running, is by executing “sudo service cron status” from the command line. If you’re using a different version of Linux to host Nextcloud, the concept is the same, but the actual command might be different.

You should get something like this.

Mar 16 07:25:02 nextcloud CRON[9580]: pam_unix(cron:session): session closed for user www-data
Mar 16 07:30:01 nextcloud CRON[9590]: pam_unix(cron:session): session opened for user www-data(uid=33) by (uid=0)
Mar 16 07:30:01 nextcloud CRON[9592]: (www-data) CMD (php /var/www/nextcloud/occ preview:pre-generate)

Here we can see that both of my CRON tasks (the general Nextcloud maintenance and thumbnail generation) were being called with the right user context (www-data), and as far as CRON was concerned working properly. But to see what’s actually happening, and why it was failing silently, we need to execute a different command: “sudo -u www-data php -f /var/www/nextcloud/cron.php“.

After which I see the following.

This version of Nextcloud is not compatible with php 8.2<br/>You are currently running 8.2.3.

Great, now we have something to work with. I must have accidentally set the default PHP version to 8.2.3; maybe when I updated the OS? Fortunately fixing this is very easy. Run “sudo update-alternatives –config php“, which should show something that looks like this:

Choose the number associated with the maximum version of PHP that the rev of Nextcloud you’re running is cool with, and you should be good to go. In my case, I’m using Nextcloud 25, so the right choice is PHP 8.1 (or 5 on this list).

Then confirm that everything is working correctly by re-executing “sudo -u www-data php -f /var/www/nextcloud/cron.php“. It might take a while, but assuming the command executes without popping errors, you should now be able to confirm that Nextcloud is happy on the CRON status page.