CRON JOB

CRON JOB

by Andre Nel -
Number of replies: 18

Hi,


I have been struggling with getting course completion working,  every post ive read says it is most likely the cron job that isn't running.  On the Moodle Documents it lists what the cron should be but i have tried those and they haven't worked.

I am using cpanel and the cron that is default is the following, /opt/cpanel/ea-php71/root/usr/bin/php -q /home/pilotlry/public_html/admin/cli/cron.php which is set to run every minute.

My customer is on my case because no badges are being issued to students who have completed the courses.

Attachment Cron.JPG
Average of ratings: -
In reply to Andre Nel

Re: CRON JOB

by Mitsuhiro Yoshida -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Translators

Hi Andre,

Could you try the following command on your cPanel Cron Jobs setting?

/usr/local/bin/ea-php71 /home/pilotlry/public_html/admin/cli/cron.php
In reply to Mitsuhiro Yoshida

Re: CRON JOB

by Andre Nel -

Hi,

Thanks

I tried that and still not working. 

In reply to Andre Nel

Re: CRON JOB

by Ken Task -
Picture of Particularly helpful Moodlers

You cPanel should have a 'Terminal' icon which is for using command line on your server.

When first clicking, you should find yourself in your home directory.

Server is using Easy Apache for the purpose of running multiple versions of supported PHP.  The cron needs to find php-cli and not the php executable that's used by Apache for the web.

So first command to use:

which php [ENTER]

That will show the path to the first php executable it finds.

Let's say that shows /usr/bin/php

Let's find out if that is for the web or cli ...

/usr/bin/php -v

**IF** the output of that does **NOT** show PHP 7.1.26 (cli) ... see the CLI in ()?  that's not the CLI PHP needed to run cron.

Next command ... this one might take some time ... let it run.

find / -name php

I don't run a system that uses Easy-Aapche so I cannot show exactly what that command would out put, but you will probably see more than one line and in the lines a reference to ea-something.

Is here one for /usr/local/bin/php?

If so, try /usr/local/bin/php -v

Do you see the correct version of PHP (the one you want to use for Moodle) and the (cli)?   If so, that's the one you use in the setup of cron.

I've had to find the cli php on no less than 4 remotely hosted VPS servers on 4 different providers this way to get cron running as it should.   And, if running Moodle 3.6.x there is now a setting for 'path to php' which suggest one needs to set.

'spirit of sharing', Ken



Average of ratings: Useful (2)
In reply to Ken Task

Re: CRON JOB

by Andre Nel -

Hi Ken,


My cpanel doesnt have the terminal option.  im using shared hosting to currently host my website

In reply to Andre Nel

Re: CRON JOB

by Ken Task -
Picture of Particularly helpful Moodlers

Are you sure?   Folks that I was helping were on shared system ... and they had terminal which was in a jail and would allow interaction for system wide things ... like the ea-php ... not configure anything system wide but for the jailed account.

Maybe help desk where you host would be so kind to investigate for you.

Your days of hosting a moodle on shared system might be over IF you cannot get access to a Terminal or out-of-normal assistance from helpdesk.

Please share with your providers helpdesk my posting ... many won't be really familiar with Moodle and it's quirks.

'spirit of sharing', Ken


Average of ratings: Useful (1)
In reply to Ken Task

Re: CRON JOB

by Andre Nel -

Hi Ken, 

The hosting company came back to me and they have given me jailed shell access.  I requested terminal as per your previous post.  


Will this work?

In reply to Andre Nel

Re: CRON JOB

by Ken Task -
Picture of Particularly helpful Moodlers

'Terminal' is the same as 'Shell' - sorta TomAtoe - TomAHtoe kinda thing. smile

You will have limited access and cannot change global config of the server, but you should be able to find out the path to php-cli to use for configuration of your cron job ... which is the purpose for getting such access.

See/read again, the posting in this thread:

https://moodle.org/mod/forum/discuss.php?d=384021#p1547882

'spirit of sharing', Ken


In reply to Ken Task

Re: CRON JOB

by Andre Nel -

Hi Ken,

What apache server would you suggest if i where to go the vps route? 


In reply to Andre Nel

Re: CRON JOB

by Ken Task -
Picture of Particularly helpful Moodlers

Simple questions don't always have simple answers ... :|

Apache ... do you mean which web server to use in a VPS?

Depends upon provider and what VPS they offer.

UnManaged ... probably means you do the updates - they give you a minimal or
an image of chosen OS with their prefernces.
Managed ... they manage the back end stuff ... like apache,DB server, PHP verisons.

If your current provider offers VPS's, best (sometimes) to stay with the devil you know
than the devil you don't.

Wouldn't go for anything less than 8 Gig memory and at least 150Gig space.  16 Gig better.

But, that depends upon you ... how many courses?  Do you charge for courses?  What's total size of your site backups ... DB dump, Moodle code, plus the biggy moodledata?

Again ... basic ... better to have more than enough and not enough.

For web server, one does have options depending upon what provider offers ... apache using php-fpm or fast-cgi or mod. Could also opt for nginx.  Due to the usage/frequency/content, etc. I have
a preference for apache as a mod.

Usually, but not always, the 'bottleneck' is the DB server and of course the DB for Moodle.

Unless a MP, wouldn't expect the provider to be very knowledgabe about Moodle - even if they
advertise as being so.

There are also questions to ask about paths upwards ... choosing the OS right now, CentOS 7 and highest Ubuntu (18.04 I think).  IF you choose to go with their default space .... whatever that is ...
IF that's not eough, can you attach a data device?   IF, you opted for 4 Gig (shame on you), can the provider offer an upgrade to 8Gig?

This is free advice ... all of it debatable am sure .... my 2 cents.

'spirit of sharing', Ken


In reply to Ken Task

Re: CRON JOB

by Andre Nel -

Hi Ken,

Thanks sorry for the simple questions.  Im new to this so dont know anything. 

 Which hosting provider would be the best option if any?

Thanks again and I appreciate all the help

In reply to Andre Nel

Re: CRON JOB

by Ken Task -
Picture of Particularly helpful Moodlers

'which hosting provider ...' ... can't answer that for you ... did hint ... 'better the devil (provider) you know than one you don't'.

The provider I would choose might be a little 'stark' for you and too much ... initially.  Not rocket science, but if you've never had any experience at IT ... even though, the day you decided to host courses in a Moodle, you picked up that hat!

You might start with simply moving from shared hosting to VPS with current provider.  They do that for you ... that's nothing you can do ... except decide the parameters/specs of the VPS.   For now, that's the path of least resistance and might be all you need.

Surely your provider is known to the public.   Check out their FAQ's, customer forums, etc. with focus on Moodle hosting - before you talk to anyone in sales! smile

'spirit of sharing', Ken



In reply to Ken Task

Re: CRON JOB

by Andre Nel -

Hi Ken,

After following the above instruction in terminal.  

Please see attached image for the results

Attachment cron3.JPG
In reply to Andre Nel

Re: CRON JOB

by Ken Task -
Picture of Particularly helpful Moodlers

Ok, your screen shot shows whatever you issued as the command found
a php 7.2.1 CLI ...
So what was the full path to that PHP?

What version of php does your moodle show it's running?
Site Admin menu -> Server -> PHP info

Best to use the same version of php-cli binary that the web server is using.   PHP info shows 7.1.xx then you need to find the path to the php-cli for that version.

The suggestion to try:
/usr/local/bin/ea-php71 /home/pilotlry/public_html/admin/cli/cron.php

was a little off in that the front part of that didn't point to a  php binary file.   Should have been:

/usr/local/bin/ea-php71/php

So what do you have in your cron job config now?

Is it working?

Have you tested cron running via command line?

'spirit of sharing', Ken

In reply to Ken Task

Re: CRON JOB

by Andre Nel -

Where would I find the full path?

The version my Moodle is running is 7.2

this is the cron command I am running:

/usr/local/bin/ea-php72 /home/learns25/public_html/pilotsoftware/admin/cli/cron.php

I also tried:

/usr/local/bin/ea-php72/php /home/learns25/public_html/pilotsoftware/admin/cli/cron.php

but neither of them are working.

How do you run it via command line, can't find anything online that shows me how

In reply to Andre Nel

Re: CRON JOB

by Ken Task -
Picture of Particularly helpful Moodlers

"How to run via command line as a test ... "

If this path is correct to your moodle code: /home/learns25/public_html/pilotsoftware/

Use ssh shell login.

cd /home/learns25/public_html/pilotsoftware/ [ENTER]

check to see what's in there:

ls [ENTER]

Do you see an 'admin' directory?   Then:

cd admin/cli/ [ENTER]

Then:

php cron.php [ENTER]

While you are there:

php -v [ENTER]

Now the following is a total guess ... cannot get accurate info so ...

What do you see when entering:

/bin/php -v

**IF** .... ***IF*** you see *something like*: PHP 7.1.27 (cgi-fcgi) then /bin/php is what your web server uses.

See the 'cgi-fcgi'?

Now let's try one more:

/usr/local/bin/php -v

**IF** you see something like: PHP 7.1.27 (cli) command found the path to the command line php and that is what you want to use in your cron command:

/usr/local/bin/php /home/learns25/public_html/pilotsoftware/admin/cli/cron.php

That's *IF* you have shared the correct path to the moodle instance.

'spirit of sharing', Ken

In reply to Ken Task

Re: CRON JOB

by Andre Nel -

Hi Ken,

I ran both the last commands and came up with the following in the image attached

Attachment Capture.JPG
In reply to Andre Nel

Re: CRON JOB

by Ken Task -
Picture of Particularly helpful Moodlers

Should community volunteers, "Give fish" or "teach how to fish"?

We know that cron job in moodle must be run by php-cli.

Which command that you issued showed php-cli?

Using that information, which /path/to/php-cli should you use
in the set up of your cron?

Login to site as admin level.
Go to Server - Notifications
Is here a notice that the cron job has not been run in the last 24 hours?

Official docs on cron:
https://docs.moodle.org/36/en/Cron
https://docs.moodle.org/36/en/Cron#Working_out_the_Moodle_cron_command

From what I've been able to slueth ... your hosting is Inmotion Hosting.
Does your hosting provider have any FAQ's/docs/customer forum, etc.
where one can get info about the platform one has chosen to host on such things
as cron jobs.

Hmmm ... looks like they do!
https://www.inmotionhosting.com/support/edu/cpanel/how-to-run-a-cron-job

Just so others don't think am being rude ...

Have sent the OP a PM with a one time offer ... looksee for free!

'spirit of sharing', Ken

In reply to Ken Task

Re: CRON JOB - closed

by Ken Task -
Picture of Particularly helpful Moodlers

First, the 'freebie look-see' has been completed.

To OP: there is a setting now in 3.6.x for 'path to php-cli' in moodle config that should contain the path to php-cli.

Site administration -> Server -> System paths
Path to PHP CLI should be set to: /usr/local/bin/php

That setting isn't auto-discovered by moodle.

Cron job ... which was op's conclusion (not running as it should) as to why badges weren't being awarded ... was perhaps configured correctly to begin with ... but I did make sure it was and tested.

For those with the latest version of cPanel, there is a terminal icon that will log one into the site via shell in a browser window.   A which php did find/point to: /usr/local/bin/php.

Site uses EasyApache ... which uses .htaccess files to set version of php for a domain/site:
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php72” package as the default “PHP” programming language.

The cron job set up in cPanel actually provided customer specific example showing customers login/paths ... just didn't show the specific path to customers moodle.

This shared for those that might be hosted on InMotion Hosting or other hosting sites that use cPanel and EasyApache.

Page at https://docs.moodle.org/36/en/Cron_with_web_hosting_services already says needs updating.

Only hoster specifically mentioned is 1and1

https://docs.moodle.org/36/en/Cron_on_1and1_shared_servers

Good hosters (like InMotion) do have docs of their own and are worth the ops time to locate and bookmark/favorite or whatever one does to keep a link.

In addition, this particular site had mod-security on for all domains ... OP opted to turn that off.  So we may never know if it was mod-security that caused the issue or cron not running properly and frequently enough nor not.

'spirit of sharing', Ken