Fresh Install Ubuntu 20.04 Moodle System Errors

Fresh Install Ubuntu 20.04 Moodle System Errors

by Triston Line -
Number of replies: 5

Following this guide: https://docs.moodle.org/310/en/Step-by-step_Installation_Guide_for_Ubuntu I've installed Moodle 3.9.3 (Build: 20201211) but upon inspecting my "system status" (Site Administration > Reports > System Status (IP/report/status.php) I see an error:

Status: Critical
Check: Cron running
Summary: The admin/cli/cron.php script has never been run and should run every 1 min. 
Action: (blank)


The Cron.php file exists in IP/admin/cli/cron.php

I have enabled debugging but I don't see any additional information anything. Cron is running:

ps aux | grep -i cron
root ... Dec16 0:01 /usr/sbin/cron -f

Thank you for your time, please help me enable or repair cron in Moodle. This is a fresh installation of both Ubuntu 20.04 server x86 and Moodle. I have not found anything online relating to the error other than someone with a container, which I do not wish to use. 

Attachment Error Screenshot Moodle Cron.png
Average of ratings: -
In reply to Triston Line

Re: Fresh Install Ubuntu 20.04 Moodle System Errors

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

Cron is running:

ps aux | grep -i cron
root ... Dec16 0:01 /usr/sbin/cron -f

The language is a bit confusing, the above process is the operating system's cron process.

The cron Moodle is warning about is the Moodle cron script which needs to be set up. This is probably a case of following the instructions. You can run it manually which might help you determine the correct paths for your server. The command to run it manually is probably something like:

# sudo -u www-data /usr/bin/php /srv/www/moodle/admin/cli/cron.php

The above example assumes that 1) www-data is the user the web server runs PHP scripts as, 2) the PHP executable is /usr/bin/php and 3) the Moodle source code folder is /srv/www/moodle. If it runs correctly you should see output ending:


Cron script completed correctly
Cron completed at 21:24:02. Memory used 28.9MB.
Execution took 1.400291 seconds


In reply to Leon Stringer

Re: Fresh Install Ubuntu 20.04 Moodle System Errors

by Triston Line -
Hi Leon,

Your assumptions are correct except for the default httpd (apache2) path is used (/var/www/html/moodle) and cron.php runs correctly. I also previously tried running it via the web (http://ip/admin/cli/cron.php) and was directed to "Command line scripts can not be executed from the web interface". I found this interesting because I had specifically inserted /usr/bin/php into Moodle's settings, though I currently forget where.

Just so you know, the guide I linked also instructs the user to change ip/moodle/ to ip/ by changing the apache2 DocumentRoot from /var/www/html to /var/www/html/moodle, and by modifying the Moodle config.php to have http://ip instead of http://ip/moodle but it is considered optional.

The output from: "# sudo -u www-data /usr/bin/php /var/www/html/moodle/admin/cli/cron.php" was a whole bunch of tasks and the end output was similar to yours:
"Cron script completed correctly
Cron completed at 20:17:09. Memory used 63.7MB.
Execution took 14.569713 seconds"

Thanks for your help, my Cron critical error has changed to a warning after waiting a couple minutes and writing this post. So something other than permissions is causing this to not run perhaps. 

EDIT: I've decided to make a temporary fix by installing a Linux crontab * * * * * /path/moodle-cron.sh and it simply added your command into the moodle-cron.sh smile so until this problem is solved, Linux will be my friend. Please let us find a real solution however, because this is technically not secure or realistically a good solution in production (which is where this VM is headed). 

Triston
In reply to Triston Line

Re: Fresh Install Ubuntu 20.04 Moodle System Errors

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

Do you mean that a warning message is still being shown?

The command to be run by the operating system's cron should go in www-data's crontab. Use the command crontab -u www-data -e to edit this. The crontab entry would then be:

* * * * * /usr/bin/php /var/www/html/moodle/admin/cli/cron.php >/dev/null

This is explained in the documentation.

It's OK to use a script in the crontab entry but you should ensure this is in the correct user's crontab, i.e. www-data. Do not put it in the (default) root crontab with an entry starting sudo -u www-data ….

If there are still problems please tell us what errors or warnings you see, and tell us exactly how you set up the crontab: the command used to edit it, the entry that was added, and the contents of any script used for this.

You need to disable Cron execution via command line only to run the cron in the browser, this is also explained in the documentation.

In reply to Leon Stringer

Re: Fresh Install Ubuntu 20.04 Moodle System Errors

by Triston Line -
Good morning Leon,

"The command to be run by the operating system's cron should go in www-data's crontab." Thank you yes, later I had installed it there yesterday evening after some thought.

"This is explained in the documentation." And yet in the fresh installation guide for Ubuntu 20.04, it is not present. I see now that the general installation guide includes a brief, and still incomplete in my opinion, section about Cron in the "Remaining Tasks" section:
"Moodle's background tasks (e.g. sending out forum emails and performing course backups) are performed by a script which you can set to execute at specific times of the day." https://docs.moodle.org/310/en/Installing_Moodle#Remaining_tasks

However, the Ubuntu 20.04 guide includes absolutely 0 statements about setting up Cron. This is an issue, please let me know if there is any way that we can signal to the document maintainer that the documentation needs another small heading detailing the addition of a new crontab into the Linux system's cron, under the webserver user's account. 

"You need to disable Cron execution via command line only to run the cron in the browser" yes I had only accessed the link to see if the file existed originally, and the output was also to display that the installation truly has followed the installation steps from the documentation.

Thank you for your time, it may be important to also specify to new users that Moodle uses Linux crontab, and not its own version of cron which must be installed- as well as explain that the web installer does not currently install a crontab script on its own. For example, some of the projects that I've worked with in the past rely on "at" instead of crontab, but continued to refer to those tasks as crons despite not using the crontab system- since then I only expect something explicitly stating such details especially when it is not included in the documentation. 

Triston