cron problems

juanma

New member
Joined
Dec 13, 2010
Messages
6
hello there. I'm new into this forum, so, please, be patient. I have installed Moodle and set the cron job in the panel. Yet I get no messages in my mail. The hosting company tells me this:

/usr/local/bin/php /home/langserv/domains/juanmacampos.com/public_html/admin/cron.php

Warning: require(../config.php): failed to open stream: No such file or directory in /home/langserv/domains/juanmacampos.com/public_html/admin/cron.php on line 45

Warning: require(../config.php): failed to open stream: No such file or directory in /home/langserv/domains/juanmacampos.com/public_html/admin/cron.php on line 45

Fatal error: require(): Failed opening required '../config.php' (include_path='.:/usr/local/lib/php') in /home/langserv/domains/juanmacampos.com/public_html/admin/cron.php on line 45

What am I doing wrong in the configuration? when run manually the cron does work perfectly.
 
Executing PHP includes in the shell needs the full path to the file

i.e

"/home/user/domains/domain/public_html/etc/config.php"

and not just

"../config.php"
 
thank you both

Thank you for your interst. The url for the cron. php in Moodle is:

www.juanmacampos.com/admin/cron.php

The configuration page in moodle is this:

$CFG->wwwroot = 'http://www.juanmacampos.com';

$CFG->dirroot = '/home/langserv/domains/juanmacampos.com/public_html'

and the cron is configured in directadmin as:

*/10 * * * * /usr/local/bin/php /home/langserv/domains/juanmacampos.com/public_html/admin/cron.php

also as:

*/10 * * * * lynx -dump http://www.juanmacampos.com/admin/cron.php >/dev/null 2>&1 (according to the hosting company, this configuration doesn't show any mistakes, yet not messages are sent to emails)

When run the cron manually, everything goes well
 
What I mean is in that cron.php file there's references to include other php files, which need the full paths to, see this post [webdeveloper.com].

Thats how I see your problem, if I'm wrong, maybe some other PHP coder will help here.

Is the script pre-made or yours?
 
For the history and others, who will search the similar solution

If you've got any inclusions in your PHP script.
You need to use full path with every include/include_once() and require/require_once()
Or just change working dir.

e.x.

Code:
cd /home/langserv/domains/juanmacampos.com/public_html/admin/; /usr/local/bin/php ./cron.php
 
Thank you for your interest

zEitEr, do you mean to just set the cron like:

/usr/local/bin/php ./cron.php

instead of:

/usr/local/bin/php /home/langserv/domains/juanmacampos.com/public_html/admin/cron.php

I'm a bit confused and I'm not an expert!! thank you:)
 
Not that. Without cd it won't work. You should run cd, otherwise all inclusions will fail.

You need to use full line:

Code:
cd /home/langserv/domains/juanmacampos.com/public_html/admin/; /usr/local/bin/php ./cron.php
 
hi Peter

What I mean is in that cron.php file there's references to include other php files, which need the full paths to, see this post [webdeveloper.com].

Thats how I see your problem, if I'm wrong, maybe some other PHP coder will help here.

Is the script pre-made or yours?


The script is not mine, is the one than comes with any Moodle installation.
 
Another piece of advice, protect your directory with the cron script.
Use .htaccess if your program has no build-in tools for limiting access to the cron script by IP.

UPD

If your script should be run from HTTP server, you can use

Code:
/usr/bin/wget -O /dev/null http://www.juanmacampos.com/admin/cron.php  >/dev/null 2>&1
 
Last edited:
Both variants, I've posted above, are working (at least should be). It depends on how the script should be executed. Some running with cron scripts should be requested from a web server, others must be run in console.

You'd better consult your program developer's documentation or FAQ http://docs.moodle.org/en/RedHat_Linux_installation

Set up the cron job

As root user edit the /etc/crontab file using vi (or another editor) OR you can add a line to the root user's "personal" crontab (don't do both!).
If you wish to place an entry in your root user's crontab use:
crontab -e
Add the following line:
*/5 * * * * /usr/bin/wget -O /dev/null http://localhost/mymoodle/admin/cron.php
(change the URL as appropriate for your site)

---
If you wish to add an entry in /etc/crontab:
Open the /etc/crontab file in an editor (vi).
Add the following line:
*/5 * * * * root /usr/bin/wget -O /dev/null http://localhost/mymoodle/admin/cron.php
(change the URL as appropriate for your site)

---
In either case, don't forget to save the file and exit (in vi that is <Esc>, then ':wq')

If the last variant is working for you, that's great.
 
Why not add this to "Sample Cron commands" in DA ?

Code:
cd /home/<user>/domains/<domain>/public_html/; /usr/local/bin/php ./cron.php
 
Why add something to a 14 year old post. Please don't up ancient threads this old.

This is no matter. 14 years old and still that info is not in the right place. The first php option dont work. Please replace it by above.
 
Last edited:
Then create a new thread about the error with current screenshot and point it out.
Also you editted your post and removed the screenshot you put in there.

It's totally unclear what you're pointing at and above issue was already solved 14 years ago.
And it's just not done to up ancient posts on forums, wrong or not wrong.
 
Sure, the screenshot below. I have DA 1.662 (2024), when I go to DA->User->Cron Jobs->Create there are "Sample Cron commands" with php example. This example dont work with multi DA installation. So it will be nice to change it from (or just add another line):

Code:
php /home/admin/domains/<DOMAIN>/public_html/script.php

to

Code:
cd /home/admin/domains/<DOMAIN>/public_html/; /usr/local/bin/php ./cron.php

Also "http" should be change to "https" protocol.

sample.png
 
Back
Top