Cron.php / Uncaught Error: Call to a member function getLogger() on null

Nextcloud version (eg, 20.0.5): 20.0.8
Operating system and version (eg, Ubuntu 20.04): shared host (CPanel), Kernel: 3.10.0-1160.6.1.el7.x86_64 x86_64
Apache or nginx version (eg, Apache 2.4.25): 2.4.46
PHP version (eg, 7.4): 7.4.16

The issue you are facing:

cron.php uncaught error (see “Logs” below)

Steps

I’ve added Nextcloud’s cron.php as a cron job (every minute !):

* * * * * php -f /home/SECRET_PATH/public_html/nextcloud/cron.php

After that in “Admin / Settings / Administration / Basic Settings / Background jobs” I’ve changed the options to “Cron”.

After that I get this message:

Last job execution ran 55 minutes ago. Something seems wrong.

On the host if a cron job produce an output, the system (CPanel) sends me an email with the output.

To make sure that the cron.php is called I wrote an echo "hello"; in the cron.php right below <?php and I started getting email with “hello” every minute.

So the cron.php is called every minute, but the Last job execution... error message still there on the web UI.

I’ve moved the echo "hello"; to different places in cron.php and it seems to me if I put the echo after require_once __DIR__ . '/lib/base.php'; the execution never reach the echo "hello";

<?php

/**
 * @copyright Copyright (c) 2016, ownCloud, Inc.
 *
 * @author Artem Sidorenko <artem@posteo.de>
 * @author Christopher Schäpers <kondou@ts.unde.re>
 * @author Christoph Wurst <christoph@winzerhof-wurst.at>
 * @author Damjan Georgievski <gdamjan@gmail.com>
 * @author Daniel Kesselberg <mail@danielkesselberg.de>
 * @author Jakob Sack <mail@jakobsack.de>
 * @author Joas Schilling <coding@schilljs.com>
 * @author Jörn Friedrich Dreyer <jfd@butonic.de>
 * @author Ko- <k.stoffelen@cs.ru.nl>
 * @author Michael Kuhn <michael@ikkoku.de>
 * @author Morris Jobke <hey@morrisjobke.de>
 * @author Oliver Kohl D.Sc. <oliver@kohl.bz>
 * @author Robin Appelman <robin@icewind.nl>
 * @author Roeland Jago Douma <roeland@famdouma.nl>
 * @author Steffen Lindner <mail@steffen-lindner.de>
 * @author Thomas Müller <thomas.mueller@tmit.eu>
 * @author Vincent Petry <pvince81@owncloud.com>
 *
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program. If not, see <http://www.gnu.org/licenses/>
 *
 */

require_once __DIR__ . '/lib/versioncheck.php';

try {
	require_once __DIR__ . '/lib/base.php';

echo "hello";

Etc

This is a shared host server (CPanel) so everything is running with a same user

Logs

error_log content after cron.php executed:

[02-Apr-2021 16:54:01 UTC] PHP Fatal error:  Uncaught Error: Call to a member function getLogger() on null in /home/SECRET_PATH/public_html/nextcloud/cron.php:163
Stack trace:
#0 {main}
  thrown in /home/SECRET_PATH/public_html/nextcloud/cron.php on line 163

Question

What is going on? How can debug this issue?

This led me to the solution: Cronjob is not working by an issue with php - #14 by kriszy

in my case:

* * * * *  /usr/local/bin/ea-php74 -f /home/SECRET_PATH/public_html/nextcloud/cron.php