Select Page

Cron – Moodle

Cron setting in the Moodle backend

Log in as administrator. Go to Site Administration > Security > Site Security Settings

Scroll down to find the entries: “Cron execution via command line only”, and
“Cron password for remote access”

If you want to access it via the browser, put a password. If not, just check “cron execution via command line only.”

https://docs.moodle.org/34/en/Site_security_settings

How to set up a cron job in Moodle

https://docs.moodle.org/33/en/Cron

https://www.easycron.com/

https://moodle.org/mod/forum/discuss.php?d=228772

How to find the path for PHP for Cron job on bluehost.com

See this bluehost.com article: Cron Jobs with PHP and other File Types

https://my.bluehost.com/hosting/help/168

On moodle.org, they give the following generic command for setting up a cron for a moodle site.

/usr/bin/php /path/to/moodle/admin/cli/cron.php

The first part, “/usr/bin/php “, is the PHP path. On bluehost.com, they recommend just putting php alone as in the following example:

php /home/username/public_html/cron.php

That is from this bluehost.com link: https://my.bluehost.com/hosting/help/168

I tried it and it worked.  See below for my cron path.

How I set up a Cron job on Bluehost.com

I used the following generic command from moodle.org.

/usr/bin/php /path/to/moodle/admin/cli/cron.php

Notice that the generic command means something. It means that if you go to the moodle folder, you will see a folder called admin, go into that folder to see a folder called cli, in the cli folder is the file named cron.php. In essence, you are spelling out the path to be used, moodle > admin > cli > cron.php

As shown above, the specific version of the path for bluehost.com is as follows

php /home/username/public_html/cron.php

My moodle site wasn’t in the public_html but within a folder that was in the public_html. My cron path has to show that.

The cron path starts with the home directory which on my blue has the format “/home#/username”  where # is a number like 2.

The final version of the cron job command I used was,

php /home2/username/public_html/moodle_folder/admin/cli/cron.php

There is just one space between php and the home directory name.

Inside the cPanel, I went to Advanced > Cron Jobs. Inside cron jobs, “Add a New Cron Job”. That’s where I added the cron job command above.

Watch this youtube video.

How to know if your Cron job is running well on bluehost.com

To know if my cron job is running well, I called and asked bluehost.com and they didn’t have any way to do so. I created a Cron Job that runs every minute and then added my email. I received emails that showed that the Cron Job was running. If it is running, it will send you a detailed page with the activities that have been performed. When I got that coming to my email right away and looked and saw that it was running properly, I went and removed my email so that I don’t get emails anymore. I also made the cron job to be once a week. Running cron jobs too frequently may slow things down.

How I ran a Moodle Cron job on Godaddy VPS

It’s pretty much the same as on Bluehost. In the cPanel, scroll down to the ADVANCED section > Cron Jobs. Click on Cron Jobs and go down to fill out the form. They provide a general example to use, which is:

/usr/local/bin/php /home/user/public_html/path/to/cron/script

the user is written out, e.g. orphanst was one an old user of mine with another hosting company. In Godaddy it’s different. Replace that name in the path. In Godaddy, my site is currently in the public_html even though I plan to change that soon.

the modified Cron job used based on the path above was:

/usr/local/bin/php /home/user/public_html/admin/cli/cron.php

And that worked!

The path makes sense!
Notice that the generic command means something. It means that if you go to the home/user, you will find a folder called public_html, in the public_html, you will see a folder called admin, go into that folder to see a folder called cli, in the cli folder is the file named cron.php. It is that command that you want to run. In essence, you are spelling out the path to be used, home/user > public_html > admin > cli > cron.php

Setting up a cron job for WordPress