Cron doesn't work with $CFG->wwwroot = 'http://'.$_SERVER['SERVER_NAME'];

Cron doesn't work with $CFG->wwwroot = 'http://'.$_SERVER['SERVER_NAME'];

by Guilherme Freitas -
Number of replies: 5

Hi everyone, 

I need to access my Moodle from different URLs and I found on web - cause my PHP skills are barely enough to set up Moodle basics - the http://'.$_SERVER['SERVER_NAME'];  solution. However, it seems like Cron doesn't work automatically when the wwwroot isn't a absolute value. 


Is it anything that I can do to solve it? It's really needed that I can access my Moodle from multiple URLs. 


Thank you all

Average of ratings: -
In reply to Guilherme Freitas

Re: Cron doesn't work with $CFG->wwwroot = 'http://'.$_SERVER['SERVER_NAME'];

by Jez H -
When you say "multiple urls" do they each have their own Moodledata and Databases, i.e. one Moodle code base but separate sites?

If not, that is if you have ONE moodle database on different domains I think you are storing up trouble for yourself.

The reason your wwwroot is not working maybe because you are calling via the command line as opposed to calling via the URL?

If so there is a way to get it to set the domain on the command line but I cannot remember how that was done (sorry).

Another way to call cron is using wget to pull down the URL which would work if you had an entry for each separate domain, for example

wget http://domainone/admin/cron/php

You would want to stagger them to call at different times.

The other thing with wget is by default it will store / download copies of the cron.php output from Moodle which you may not want.


In reply to Jez H

Re: Cron doesn't work with $CFG->wwwroot = 'http://'.$_SERVER['SERVER_NAME'];

by Guilherme Freitas -

Sorry, I didn't give you much information about my case. 

It's the same database. It's, actually, the same Moodle platform, it's just accessed by different URLs to avoid any misspelling from the users. 


The URLs that I need to access my Moodle from are: 

www.eadmydomain.com 

ead.mydomain.com

www.ead.mydomain.com


I could use a redirect page and set one of them as the original URL, I know... but I really want the student to wouldn't be able to notice the redirection (or the URL change).


Yes, the Cron error occurs only when I try to access it by command line. It says: 

Debug info: 
Error code: wwwrootslash
Stack trace: * line 463 of /lib/setuplib.php: moodle_exception thrown
* line 753 of /lib/setuplib.php: call to print_error()
* line 759 of /lib/setup.php: call to initialise_fullme()
* line 26 of /config.php: call to require_once()
* line 33 of /admin/cli/cron.php: call to require()


Again, Thank you for your attention. 

In reply to Guilherme Freitas

Re: Cron doesn't work with $CFG->wwwroot = 'http://'.$_SERVER['SERVER_NAME'];

by Perry Way -

Moodle will only run right if you provide a single URL. There are cache records that occur on the back side that related to that value so you can't have a dynamic value like you tried. If you want to run multiple URL's/paths, you will need to reinvent a lot of internals in Moodle. Better to redirect the other paths/urls to the single URL you will use.

In reply to Jez H

Re: Cron doesn't work with $CFG->wwwroot = 'http://'.$_SERVER['SERVER_NAME'];

by Guilherme Freitas -

Sorry, I didn't give you much information about my case. 

It's the same database. It's, actually, the same Moodle platform, it's just accessed by different URLs to avoid any misspelling from the users. 


The URLs that I need to access my Moodle from are: 

www.eadmydomain.com 

ead.mydomain.com

www.ead.mydomain.com


I could use a redirect page and set one of them as the original URL, I know... but I really want the student to wouldn't be able to notice the redirection (or the URL change).


Yes, the Cron error occurs only when I try to access it by command line. It says: 

Debug info: 
Error code: wwwrootslash
Stack trace: * line 463 of /lib/setuplib.php: moodle_exception thrown
* line 753 of /lib/setuplib.php: call to print_error()
* line 759 of /lib/setup.php: call to initialise_fullme()
* line 26 of /config.php: call to require_once()
* line 33 of /admin/cli/cron.php: call to require()


Again, Thank you for your attention. 

In reply to Guilherme Freitas

Re: Cron doesn't work with $CFG->wwwroot = 'http://'.$_SERVER['SERVER_NAME'];

by Bret Miller -
Picture of Particularly helpful Moodlers

You could rewrite one URL to the other using .htaccess. Moodle really only wants to run under one URL.