Cronjob is not working by an issue with php

cron
hosting

#1

Hi,

my cronjob in nextcloud is not working. By starting it directly over the prompt i got:

php7.1 -f ~/svn/cloud/cron.php


Fatal error: Uncaught Error: Call to a member function getLogger() on null in /homepages/11/d65873472/htdocs/svn/cloud/cron.php:160
Stack trace:
#0 {main}
thrown in /homepages/11/d65873472/htdocs/svn/cloud/cron.php on line 160

What is the reason/origin?
The installation is hostet at 1&1 as webspace
Do you need mor informations?

Thanks for your help!

Regards


#2

Do you have this declarations in your config.php?

‘logfile’ => ‘<path to your data directory>/nextcloud.log’,
‘loglevel’ => 2,

The line 160 in the cron.php is already an exception, so something else is broken too. Did you start the cronjob by the user that owns the directory? What system is this running on? The path /homepages looks strange.


#3

Hi,

the system runs under
SMP Debian 3.16.59-1~ui80+1 (2018-10-03) x86_64.
Yes I started the cronjob as the same user - I have no other choice.
Since my nexcloud runs at a webhoster contract, the side is hosted together with other under this path ‘homepages/…’

My home directory is located deeper int the tree.
/homepages/11/d65873472/htdocs.

The systems php version is
php --version PHP 4.4.9 (cgi-fcgi) (built: Nov 7 2018 13:27:00)

I have to call the script explicitly with php7.1 - I don’t if this is a critical point.
I set the loglevel to two, but i dont’t see the log file at the specified path.


#4

Depends on your NC Version. E.g. 15 does not support php below version 7 - https://docs.nextcloud.com/server/15/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation, but NC 13 supports php Version 5.6 - https://docs.nextcloud.com/server/13/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation. In Any way it is higher than 4.4.9.


#5

The cronjobs didn’t run under a former Version of nc, so I try to figure out why.
But there is one importatnt point: At the mamagement site of my hoster I can define that the domain for nextcloud uses php7.x. But when I access my sites via ssh, there is php 4.4.9 set as default. The question is which on is used by the cron jobs.
Can I force the cronjobs to use a specific php version? I know that I did it by php7.1 cron.php but how are other script called from the cron.php?


#6
whereis php #shows you where PHP is located
php: /usr/bin/php7.0 /usr/bin/php...

Try to set instead of php full path like: /usr/bin/php7.0


#7

The cron job must run as the same user as the webserver, that would be www-data on a debian system. To call the command manually, use

sudo -u www-data php7.1 -f ~/svn/cloud/cron.php

To setup the cron job, use

sudo crontab -u www-data -e

Did you do that?


#8

There is no sudo avaiable:
sudo -u www-data php7.1 -f ~/svn/cloud/cron.php
-bash: sudo: command not found


#9

Login as root and execute the following command:

apt-get install sudo

This should fix the -bash: sudo: command not found error message.


#10

Yes I tried, but unfortunately it leads to the same result:

’ $ /usr/bin/php7.1 ~/svn/cloud/cron.php
X-Powered-By: PHP/7.1.25
Content-type: text/html; charset=UTF-8


Fatal error: Uncaught Error: Call to a member function getLogger() on null in /homepages/11/d65873472/htdocs/svn/cloud/cron.php:160 Stack trace: #0 {main} thrown in /homepages/11/d65873472/htdocs/svn/cloud/cron.php on line 160
'

#11

I have just user permissions and just a few basic tools, the hoster has limitied the available command line tools.


#12

In that case it may be possible that sudo is installed but you may not use it due to being restricted.

Please try the following:

su - www-data -c "/usr/bin/php7.1 -f ~/svn/cloud/cron.php"


#13

I can enter the command without getting an error message but it has no effect. In the Settings in the nc web Interface is shown that the cron Job was not done.
As Workaround I activated the cronjob via AJAX.