Error : CronJob - Command line scripts can not be executed from the web interface

Error : CronJob - Command line scripts can not be executed from the web interface

door Sarel van der Merwe -
Aantal antwoorden: 10

Hi,

Error : CronJob - Command line scripts can not be executed from the web interface

Im getting this notification :  The admin/cli/cron.php script has never been run and should run every 1 min. 

CentOS Linux 7.9.2009
PHP 8
Moodle (Latest version 3.11.5)

This is my cron job 

/usr/bin/php /home/domain name/public_html/admin/cli/cron.php


off topic  ..... Is this discussion forum also build with Moodle




Gemiddelde van de beoordelingen:  -
Als antwoord op Sarel van der Merwe

Re: Error : CronJob - Command line scripts can not be executed from the web interface

door Howard Miller -
Foto van Core developers Foto van Documentation writers Foto van Particularly helpful Moodlers Foto van Peer reviewers Foto van Plugin developers
What it says... if you are typing that into a web browser then it doesn't work.

If the cron job line is what is in your crontab then it looks potentially ok. What happens if you type that line on the command line?
Gemiddelde van de beoordelingen:  -
Als antwoord op Howard Miller

Re: Error : CronJob - Command line scripts can not be executed from the web interface

door Sarel van der Merwe -
I created the cron job under virtualmin / webmin modules / Scheduled Cron Jobs.
Told it to save and run now inside virtualmin
command : /usr/bin/php /home/techskill.co.za/public_html/admin/cli/cron.php

websitename :10000/cron/exec_cron.cgi?idx=135&xnavigation=1
Gemiddelde van de beoordelingen:  -
Als antwoord op Howard Miller

Re: Error : CronJob - Command line scripts can not be executed from the web interface

door Sarel van der Merwe -
I managed to run the old cron job (no CLI)
/usr/bin/wget http://domain/admin/cron.php

output
--2022-02-17 15:59:00-- http://domain/admin/cron.php
Resolving
Connecting to domain:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: 'cron.php.1'

0K 10.1M=0s

2022-02-17 15:59:00 (10.1 MB/s) - 'cron.php.1' saved [84]
Gemiddelde van de beoordelingen:  -
Als antwoord op Sarel van der Merwe

Re: Error : CronJob - Command line scripts can not be executed from the web interface

door AL Rachels -
Foto van Core developers Foto van Particularly helpful Moodlers Foto van Plugin developers Foto van Testers
I thought PHP 8.0 was not supported yet:
MDL-70745 - PHP 8.0 support is being implemented for Moodle 3.11 and later releases. Hence it's still incomplete and only for development purposes
Gemiddelde van de beoordelingen: Useful (1)
Als antwoord op Sarel van der Merwe

Re: Error : CronJob - Command line scripts can not be executed from the web interface

door Visvanath Ratnaweera -
Foto van Particularly helpful Moodlers Foto van Translators
Als antwoord op Visvanath Ratnaweera

Re: Error : CronJob - Command line scripts can not be executed from the web interface

door Sarel van der Merwe -
I have downgraded php 8 to php 74

under ' Dashboard ► Site administration ► Security ► Site policies ' I deselected 'Cron execution via command line only'.
According to documentation I must use the old cron job with password.

http://site.example.com/admin/cron.php?password=opensesame... isn't this depreciated.
I have done the setting and saved it...

Still getting Command line scripts can not be executed from the web interface.
It is as if the system haven't updated and applied the setting... maybe will only apply when the cron run.
Gemiddelde van de beoordelingen:  -
Als antwoord op Sarel van der Merwe

Re: Error : CronJob - Command line scripts can not be executed from the web interface

door Visvanath Ratnaweera -
Foto van Particularly helpful Moodlers Foto van Translators
Als antwoord op Sarel van der Merwe

Re: Error : CronJob - Command line scripts can not be executed from the web interface

door Leon Stringer -
Foto van Core developers Foto van Particularly helpful Moodlers

Where are you seeing the Command line scripts can not be executed from the web interface message? Can you share a screenshot of the message? And can you share a screenshot of the cron job command? (Crop or obscure anything you don't want to share on the Internet).

Command line scripts can not be executed from the web interface happens when admin/cli/cron.php is run but PHP has a remote IP address in its environment. Normally when PHP is run on the command line there's no IP address, there is one if PHP is run via a web page. I had a strange situation recently were – when trying to use Run now in the browser – the PHP command line executable was being passed the IP address from the browser request. I don't understand the "websitename :10000/cron/exec_cron.cgi?idx=135&xnavigation=1" part, but I'm wondering if it means admin/cli/cron.php is being run in a web environment and getting passed an IP address.

Yes, running cron via the command line is preferred, but if running it with Wget works then it should be fine to do that instead. You may wish to use the option -O cron.out so that you don't end up with lots of cron.php.1, cron.php.2, etc. files (/usr/bin/wget -O cron.out https://domain/admin/cron.php).

Gemiddelde van de beoordelingen:  -
Als antwoord op Sarel van der Merwe

Re: Error : CronJob - Command line scripts can not be executed from the web interface

door Ken Task -
Foto van Particularly helpful Moodlers

Pardon intrusion ...

+1 for NOT running PHP 8.X

Do not run wget ... that's been depreciated.  Or so it's been said by a Moodle HQ programmer.   However, comments in /admin/cron.php still show wget.  Please ignore the comment/suggestion.

cron jobs set up in webmin do work, just can't run them via Webmin to see them work.

That's because webmin is perl.

One way to check .. login to webmin
Look at left column bottom for a > icon - that's terminal.

From the terminal prompt type: which php [ENTER]
That should show a path to php-cli ... something like /usr/bin/php
To check that is php-cli, type and enter this:

/usr/bin/php -v

Response to that command should show in response (php-cli)
using that path issue this command:

/usr/bin/php /home/techskill.co.za/public_html/admin/cli/cron.php

If that full path to php-cli is correct and if the full path to admin/cli/cron.php
is correct it will work.   That's what should be entered in the Webmin interface.

'SoS', Ken

Gemiddelde van de beoordelingen: Useful (1)
Als antwoord op Ken Task

Re: Error : CronJob - Command line scripts can not be executed from the web interface

door Sarel van der Merwe -
Thank you, got it working.

My version of Webmin dont have access to terminal or it's blocked..
The work around, insert this in php program and run and test
<?php echo shell_exec('/usr/bin/php -v'); ?> Check version of PHP
<?php echo shell_exec('/usr/bin /path to /admin/cli/cron.php'); ?> run cron job.. to see if it work..
Gemiddelde van de beoordelingen: Useful (1)