Multiple Moodles, One Database

Multiple Moodles, One Database

by Tim Williams -
Number of replies: 13
Picture of Plugin developers
For various funding/presentational reasons, I need to get our moodle set up to operate through two different URL's with two different skins (both hosted on the same server though). My immediate thought was that I could put idential copies of moodle (excepting the contents of the configured skin and some of the parameters in config.php) into the two websites and then simply point both at the same data directory and database.

Does anybody know of anything in moodle that would cause problems if there were two seperate installations pointing at the same databsase and data directory ?
Average of ratings: -
In reply to Tim Williams

Re: Multiple Moodles, One Database

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
That should work fine.  Just make sure that the code really is identical, and that you upgrade them identically.
In reply to Tim Williams

Re: Multiple Moodles, One Database

by W Page -
Hi!

Another option would be to change the table name prefix in one of the installations so that you would use 1 database but have 2 different set of tables for each install.

For example, let's say you have the following:
Database Host - db33.mymy.net
Database Name - mountain
Database UserName - tim
Database PassWord - abcde

You can make the following changes in one of the "config" files.

WEBSITE I

$CFG->dbtype = 'mysql'; // mysql or postgres7 (for now)
$CFG->dbhost = 'db33.mymy.net'; // eg localhost or db.isp.com
$CFG->dbname = 'mountain'; // database name, eg moodle
$CFG->dbuser = 'tim'; // your database username
$CFG->dbpass = 'abcde'; // your database password
$CFG->prefix = 'mdl_'; // Prefix to use for all table names

WEBSITE II

$CFG->dbtype = 'mysql'; // mysql or postgres7 (for now)
$CFG->dbhost = 'db33.mymy.net'; // eg localhost or db.isp.com
$CFG->dbname = 'mountain'; // database name, eg moodle
$CFG->dbuser = 'tim'; // your database username
$CFG->dbpass = 'abcde'; // your database password
$CFG->prefix = 'mdl2_'; // Prefix to use for all table names

You can name either table prefix anything you want. I just used
"mdl" and "mdl2" an examples ("mdl"is also the default prefix in the "config.php" file).

WP1

CORRECTED: August 2, 2004 WP1
In reply to W Page

Re: Multiple Moodles, One Database

by Chardelle Busch -
Picture of Core developers

Wow,

Thanks so much, Tim, for posting this.  I had posted a similar question awhile back, but was not able to get a solution, probably because I didn't know how to ask it.  (One Moodle, Multiple headers.) 

I have a couple of questions, though.  Tim, by "skin" to you mean a different theme for each install? And are the changes you mention in the config file similar to what WP1 has delineated? 

And, WP1, what exactly does the Prefix to use for all table names do/mean?

It looks like you would have two installs of moodle--each with their own theme(?), but change the config files for each so that they both point to the same database, yet each to its own Prefix for table names(?).  Am I close here at all?

Thanks for your help,

Chardelle

In reply to Chardelle Busch

Re: Multiple Moodles, One Database

by W Page -
QUOTE
"It looks like you would have two installs of moodle--each with their own theme(?), but change the config files for each so that they both point to the same database yet each to its own Prefix for table names(?). Am I close here at all?" Chardelle Busch

You go girl!!!

All the prefixes do is let you know which database belongs to which site. That way you should be able to determine which site database you are making changes in or which one you need to repair or even delete.

The downside is, if you want to delete the database of one of the sites for whatever reason, you will have to click the box next to each table you need to remove (about 80) so you do not delete the set of tables for the other site's database you want to preserve.

If you have more than one database you would just delete the site database you wanted to remove. It is easier this way. Less "click" effort. smile

ONE DATABASE

Approach
Number of Sites
Number of DB
DB prefix
Result
Tim
2 or more
1
Same for each site in "config.php"
One set of tables for two different sites on one database
WP1
*
2 or more
1
Different for each site in "config.php"
Two or more sets of tables for two or more different sites on one database. Each table set has a different prefix name.

* Take a look at the attached image. You will see parts of different table sets. One has the prefix "mdl_" the other "mdl14dev_". Both are on one database. Each set of tables serve one of two sites.

TWO OR MORE DATABASES


Approach
Number of Sites
Number of DB
DB prefix
Result
Usual
Multiple
Multiple
Since each database has a separate name, the prefix can be the default "mdl_" in each database.
One set of tables in each different database.


I know it is a bit wordy but I hope I was able to clear this up??

If anyone else has something to add to this, please do.


WP1

Attachment examble_db1.gif
In reply to W Page

Re: Multiple Moodles, One Database

by Chardelle Busch -
Picture of Core developers

Uhhhhhh........

WP1 you are a doll, what did I every do without you?  But.......  now I am confused.

"If you have more than one database you would just delete the site database you wanted to remove. It is easier this way. Less "click" effort."

Okay, now are you saying that if you have two installs, but want to "share" a database, then just delete one database and point the config file to the shared database.  I am assuming that installing Moodle automatically creates a database, and this database can subsequently be deleted if it isn't needed?

"All the prefixes do is let you know which database belongs to which site."  "You will see parts of different table sets. One has the prefix "mdl_" the other "mdl14dev_". Both are on one database."

Are you talking about two installs each with their own data (table set) but both sharing a database?  I'm still not sure about what this is.  Could you maybe explain it in terms of a course.  i.e., Site 1 has its own theme, but when its users log in, they will be going to the same course that users of Site 2 (with it own theme) go to? And the different table sets mean that...........? 

Thx and thx again

Chardelle

In reply to Chardelle Busch

Re: Multiple Moodles, One Database

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
WP1 is talking about two completely different Moodle sites.

This is quite different from the original question which is ONE site (common content and courses) appearing under two themes.

To achieve the latter you need one site set up normally, with a custom theme like "mytheme".

Then, on another web address, you set up a second Moodle, using a config.php that is almost exactly the same except for the $CFG->wwwroot. This second set of files ALSO has a "mytheme" theme folder, but it will contain different colours and styles etc. Apart from this one folder the rest of the Moodle files must be identical.
In reply to Martin Dougiamas

Re: Multiple Moodles, One Database

by W Page -
Hello All!

Chardelle, I decided to just do a full blown explnation with diagrams. I hope the attached image will help you understand what I am trying to describe. I have also taken into account Martin's comments about the $CFG->wwwroot. I am also asking him to review the image and see if the information is correct. Also, any Moodler who would like to comment, their input will be welcomed. I intend to submit it as a "HowTo" in the Document Course.

There is also a PDF file of the images below here (temporary) if it is easier to read that way.

Thanks in advance.

WP1

Corrected WP1 August 4, 2004
Attachment moodle_db_setup_01.gif
In reply to W Page

Re: Multiple Moodles, One Database

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
There could be some confusion of terminology here. I think what WP is suggesting is that both moodles run of the same "database", except  they point to a different set of tables based on the prefix. One of the reasons/benefits of Moodle using table prefixes is that it prevents table name clashes with other tools, particularly for people with shared hosting where you cannot create a new database, but can create new tables. Thus moodle might have a table called prefix_users (defaulting to mdl_users) and I might have some other tool that has a table called users. Because of the prefix for the tables there is no clash were both systems want to call the table users. One of the side benefits of this is that you can run two moodles off the same database but using different prefix. Thus you might run the production stable version with a prefix of simply mdl_, but run a dangerous wobbly bleeding edge test system with the prefix mdl_15 (or whatever) from the same database.


In reply to W Page

Re: Multiple Moodles, One Database

by W Page -
Hi Marcus and Tim!

Appreciate the input. Good "rephasing" of what I am trying to convey Marcus and a good explanation of why (the reasons for the decision) you want to set up the database the way you want to Tim.

Will incorporate these thoughts in the update of the chart above. I think I need another column for indications for (the reasons for) the different database setups.

More opinions please!

WP1
In reply to W Page

Re: Multiple Moodles, One Database

by Chardelle Busch -
Picture of Core developers

Thanks everybody for the clarification.

I have been wanting to do exactly what Tim has mentioned.  This can make it more cost effective for a company who would like to have their "own" customized training center, but perhaps do not have enough resources or users to afford or support their own course.  This way they can share a course (perhaps being put into groups) with other companies, but to their employees it looks like their own company site.

I'll test it out and see how it goes.

Chardelle

In reply to Chardelle Busch

Re: Multiple Moodles, One Database

by Tim Williams -
Picture of Plugin developers
> Tim, by "skin" to you mean a different theme for each install?

That's precisely what I mean.

> yet each to its own Prefix for table names(?).

In my case they would all use the same prefix, the reason being to enable the exact same content to appear on both sites with different themes, but without actually having to maintain two seperate moodle installations.

Background :

We have a number of projects which each have there own website, up till now policy has been that all the learning material goes through a single website and the other projects just push through to this one master website. However, for presentational reasons we want to be able to present the material through all the sites and make it look like it is comming from each individual site, rather than one master site. From an administrative point of view, having multiple different moodle servers (ie using either a different database or prefix) would make life difficult from a maintenance point of view. However, using the same one means you only have to maintain one database setup.

This is also a very handy thing to do if you are delivering training to a corporate customer who wanted to have there own corporately themed version of the learning material. With this technique, you could do it very quickly, with no on going maintenance problems (unless you upgrade moodle, as martin says, you need to make sure everything bar the theme and config.php is identical in each copy).
In reply to Tim Williams

Re: Multiple Moodles, One Database

by jovi . -
Hi Tim,

In this setup, what about instructors? Does this mean that if you give one client Instructor access, they will be able to see ALL the students enrolled? Even those of other clients?

If so, how can this be prevented?
In reply to jovi .

Re: Multiple Moodles, One Database

by Steve Hyndman -

I believe that is correct Jovi...using this set-up, the different Moodle installs are "looking at, and in fact, using" the same data in the same tables, so everyting would be available for both installs...sort of like two computers using the same hard drive.

This is an old thread, but I would be interested to hear how this worked. It seems like there could be problems if one person tried to change some systemwide variable because that would change the way both sites worked. For example, if one site set moodle to "force login" then all sites using that database would be forced login. 

If you need multiple moodle installs to operate "independently" then you could still use a single database, but each install would need its own tables...controlled by table prefixes...like WP explained above.

I don't have two moodle installs using a single database, but I do have 68 Wordpress blogs using a single database (13 tables each = 884 tables). I use these for a class I teach (actually three classes) so each of my students can have their own blog to practice with. There is probably some reason why I shouldn't have that many tables in a single database, but it has worked well for me for the past 6 months smile

Steve