Hallo,
sorry for my terrible English.
I have more "moodle" virtual domains an my directory structure is:
/var/www/html/main.moodle (directory with moodle installation)
/var/www/html/sub1.moodle.site -> symlink to main.moodle /var/www/html/sub2.moodle.site -> symlink to main.moodle /var/www/html/sub3.moodle.site -> symlink to main.moodle
Here is my config.php with cron functionality for multiple sites.
define('MOODLE_NO_DOMAIN', 'none');
$domain = MOODLE_NO_DOMAIN;
if ( defined('CLI_SCRIPT') && CLI_SCRIPT == true) { // CALLED FROM COMMANDLINE - cron.php etc ..
preg_match('/^(.*\/)*(.*\.moodle\.site)\/.*$/',$_SERVER['PHP_SELF'],$matches);
if ( count($matches) > 0 ) {
$domain = $matches[count($matches) - 1];
}
} else { // CALLED FROM BROWSER $domain = $_SERVER['HTTP_HOST']; } // HERE AS ABOVE FROM THOMAS VAN DEN HEUVEL
switch ($domain) {$CFG->dirroot = '/var/www/html/main.moodle';
// configuration for subdomain 1
case 'sub1.domain.com':
$CFG->dbname = 'sub1_moodle'; // if your database is called sub1_moodle for this subdomain
$CFG->wwwroot = 'http://sub1.moodle.site'; // no trailing slash
$CFG->dataroot = '/path/to/sub1data/'; // depends on where you put your datadir
break;
// configuration for subdomain 2
case 'sub2.domain.com':
$CFG->dbname = 'sub2_moodle'; // if your database is called sub2_moodle for this subdomain
$CFG->wwwroot = 'http://sub2.moodle.site'; // no trailing slash
$CFG->dataroot = '/path/to/sub2data/'; // depends on where you put your datadir
break;
// et cetera
default:
// ... redirect to info page with moodle links
}
Cron tasks must be called with absolute or relative subdomain path:
php /var/www/html/sub1.moodle.site/admin/cli/cron.php
or
php sub1.moodle.site/admin/cli/cron.php
I call all of the subdomains crons with one very simple script :
#! /bin/bash
WWW_ROOT="/var/www/html"
DIRS="sub1.moodle.site sub2.moodle.site sub3.moodle site"
for dir in $DIRS
do
echo "$WWW_ROOT/$dir"
php "$WWW_ROOT/$dir/admin/cli/cron.php"
done
I hope this post was useful.