How to use 1 moodle numerous databases and subdomains

How to use 1 moodle numerous databases and subdomains

by Rod Lawson -
Number of replies: 1

Hello,

I’ve wracked my brain looking through all of the forums and not really finding a definitive answer to my needs. First off, I’m not a programmer, so if there’s an answer it should possibly be in layman’s terms.

So far, I’ve setup my Moodle site as https://mysite/myschool and works fine.

I’ve setup the categories as separate companies and assigned managers to control their particular category. This particular setup is not ideal and I would like to try something new.

I know Moodle isn’t set up for multi-tenancy and I’m not interested in Iomad as it really doesn’t do what I want anyway.

I would like to set up Moodle so I can use multiple subdomains. For example:

mymoodle1.mysite.com its own database moodle1database

mymoodle2.mysite.com database moodle2database

Each subdomain needs to connect to Moodle and to its particular database.

I would like to use only one Moodle install, but a separate database for each subdomain.

The problem I’m having is that I don’t understand how to configure this.

This is my single moodle config file.

<?php  // Moodle configuration file

unset($CFG);

global $CFG;

$CFG = new stdClass();

$CFG->dbtype    = 'mysqli';

$CFG->dblibrary = 'native';

$CFG->dbhost    = 'localhost';

$CFG->dbname    = 'myschool;

$CFG->dbuser    = '_name';

$CFG->dbpass    = 'password';

$CFG->prefix    = 'mdlmg_';

$CFG->dboptions = array (

  'dbpersist' => 0,

  'dbport' => '',

  'dbsocket' => '',

  'dbcollation' => 'utf8_general_ci',

);

$CFG->wwwroot   = 'https://mysite.com/myschool';

$CFG->dataroot  = '/home/xxxxxxxx/moodledata';

$CFG->admin     = 'admin';

$CFG->directorypermissions = 0777;

require_once(__DIR__ . '/lib/setup.php');

// There is no php closing tag in this file,

// it is intentional because it prevents trailing whitespace problems!

I have setup the moodledata folder for my Moodle site and it has its own database as shown above.

I have setup another moodledata1 folder and have assigned it to its own database.

Is there way to call the moodledata1 instance in the config file above along with the moodledata instance with a separate domain name?

For example: mysite.com/moodle calls my main moodle

And maybe something like: moodle1.mysite.com that calls its moodle

And later add another moodledata1 folder and have moodle2.mysite.com

Can I just add something in the config file to direct each subdomain to the moodle and dedicated database?

I understand I could have a moodle install for each domain, but that seems like a lot more updating and stuff. Plus I would like to sinc each subdomain to the multi wordpress and need those as seperate domains. Not sure if that would work though.

If none of this makes sense, I can sure understand that.

Thanks for any clarification.

Rod
Average of ratings: -
In reply to Rod Lawson

Re: How to use 1 moodle numerous databases and subdomains

by Ken Task -
Picture of Particularly helpful Moodlers

Yes .. it makes sense ... one code base for multiple Moodle instances ... but one box?  Maybe not ... depends upon factors/usage you've not disclosed ... and you can't cause one doesn't know what one doesn't know! ;)

Please see:

https://docs.bullardisd.net/public/cluster/moodle.html?highlight=moodle

"Installs Moodle in a clustered environment. With this setup multiple moodle installations use the same PHP Codebase at /var/moodlewww. This allows for quicker upgrades, but does not allow moodles to be upgraded separately. Thus it is recommended that testing moodles are installed with a separate codebase."

Bullard had some known factors ... number of campuses ... number of students/teachers ... actual number of courses to be served ... etc.

How well can you tread water?

Above shows it's possible ... however ... if updating/upgrading was your *one* reason for seeking one code base multiple instances, wonder if multiple virtual apaches with separate code bases, data dirs, and DB's that were installed via git and are updated/upgraded via same (git) would really be easier ... in the long run.

Git updates to an instance take maybe a few minutes ... depending.

Git upgrades take longer ... 30 minutes at the max? ... dependencies there as well ... like compatible plugins for the version upgrading to.

Used to admin a Moodle server for a school district in South Texas that had 7 separate instances on a beefy box and could update all 7 instances with one bash shell script making backups of the code and DB just prior to each instance update.  7 instances just happened to be in subdirectories of the server but could have been virtual apaches on the same server as well.  Each campus moodle used LDAP for student and teacher authentication and each campus moodle had a campus person admin the Moodle.

Would strongly advise, which ever direction you choose, to setup sandbox implementation and see.

'spirit of sharing', Ken