General developer forum

Run multiple instances of Moodle without duplicating base code?

 
Picture of Tony Hursh
Run multiple instances of Moodle without duplicating base code?
 
You're probably wondering why I'd want to do that. smile

Here's the situation: my students are in a master's degree program aimed at working teachers. We use Moodle for course delivery in the program. I've also set up a personal Moodle server (on a commercial hosting provider) and invite my students to create their own Moodle courses there. A fair number of them have, and are using these courses with their own students.

What I'd like to do is let them have their own Moodle system with full administrative access. That would not only give them more Moodle experience, it would reduce the administrative load on me when one of their students forgets his password, or his mailbox fills up and the bounce messages start coming to me, etc.

While I don't mind helping them out now and then, I'm not charging them any money for hosting their courses (I also have a job and am trying to finish a PhD, so "free time" is a little short).

Now, I understand how to create another completely independent site using the same server and database (changing the table prefix, etc.) but that seems to require that I also maintain a second copy of all the code. That's going to chew up my alloted disk space pretty fast.

It'd be great if there were some hack that'd let me share the base code among all the installations, with only the config.php being different. I've thought of a few schemes but nothing really workable on an individual scale (e.g., adding a "site" parameter to all URLs so Moodle could tell which config.php to load, but that would require modifying almost every file in Moodle).

This might also being useful for the growing number of companies who provide commercial Moodle hosting (not only would there be less disk space used, they'd only have update one copy of the code when a new version of Moodle came out).

It's possible that I'm overlooking something blazingly obvious. I'm known for doing that from time to time. smile

Anyone got a clever way to make this work? Maybe you could do this with apache's mod_rewrite?


 
Average of ratings: -
Martin Langhoff - Sailing
Re: Run multiple instances of Moodle without duplicating base code?
 
We are running several virtualhosts using moodle with the same codebase, and a slightly hacked config file. I think I posted it some time in the past, but I can't find the original with the explanation.

We run the virtual hosts all like foo.lms.eduforge.org and bar.lms.eduforge.org so the config file uses foo_ (and bar_) as table prefixes, and as the data directory.

Two things to bear in mind:
- you need to run your cron with extra params
- you'll have to split codebases if you want to upgrade them separately

Warning: big fat (complex?) config files follow:

- moodle's config.php

- our cron invocation

- our apache virtualhost/alias config


This is my config.php:

<?PHP // $Id: config-dist.php,v 1.54 2004/05/03 14:57:11 moodler Exp $

/// EDUFORGE MOODLE LMS SETUP --- YOUR ATTENTION PLEASE!!!!
///
/// This config file supports many moodle instances from one directory
/// and one config file.
///
/// We'll get the virtualhost prefix (foo in foo.lms.eduforge.org) and use that
/// to define:
/// - DB table prefix
/// - VAR directory: /home/lms/var/$prefix/
/// - Optional config override file: you can override any config value by creating
///  a config_$prefix.php file. Be cautious, however!

// Obtain and sanitize prefix
$eduforge_prefix = $_SERVER['HTTP_HOST'];
if (isset($_ENV['HTTP_HOST'])){ // this is to support cronjobs on a per-host basis
$eduforge_prefix = $_ENV['HTTP_HOST'];
}
$eduforge_prefix = explode('.', $eduforge_prefix);
$eduforge_prefix = $eduforge_prefix[0];
$eduforge_prefix = preg_replace("/\W/", "", $eduforge_prefix);

// if there wasn't a prefix redirect to eduforge
if($eduforge_prefix == 'lms' || $eduforge_prefix=='') { //
header("Location: http://eduforge.org/");
exit;
}

///////////////////////////////////////////////////////////////////////////
//                                                                      //
// Moodle configuration file                                            //
//                                                                      //
// This file should be renamed "config.php" in the top-level directory  //
//                                                                      //
///////////////////////////////////////////////////////////////////////////
//                                                                      //
// NOTICE OF COPYRIGHT                                                  //
//                                                                      //
// Moodle - Modular Object-Oriented Dynamic Learning Environment        //
//          http://moodle.org                                            //
//                                                                      //
// Copyright (C) 1999-2004  Martin Dougiamas  http://dougiamas.com      //
//                                                                      //
// This program is free software; you can redistribute it and/or modify  //
// it under the terms of the GNU General Public License as published by  //
// the Free Software Foundation; either version 2 of the License, or    //
// (at your option) any later version.                                  //
//                                                                      //
// This program is distributed in the hope that it will be useful,      //
// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        //
// GNU General Public License for more details:                          //
//                                                                      //
//          http://www.gnu.org/copyleft/gpl.html                        //
//                                                                      //
///////////////////////////////////////////////////////////////////////////
unset($CFG);  // Ignore this line

//=========================================================================
// 1. DATABASE SETUP
//=========================================================================
// First, you need to configure the database where all Moodle data      //
// will be stored.  This database must already have been created        //
// and a username/password created to access it.                        //
//                                                                      //
//  mysql      - the prefix is optional, but useful when installing    //
//                into databases that already contain tables.            //
//
//  postgres7  - the prefix is REQUIRED, regardless of whether the      //
//                database already contains tables.                      //
//                                                                      //
// A special case exists when using PostgreSQL databases via sockets.    //
// Define dbhost as follows, leaving dbname, dbuser, dbpass BLANK!:      //
//    $CFG->dbhost = " user='muser' password='mpass' dbname='mdata'";    //
//               




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

$CFG->dbpersist = true;        // Should database connections be reused?
                                // "false" is the most stable setting
                                // "true" can improve performance sometimes


//=========================================================================
// 2. WEB SITE LOCATION
//=========================================================================
// Now you need to tell Moodle where it is located. Specify the full
// web address to where moodle has been installed.  If your web site
// is accessible via multiple URLs then choose the most natural one
// that your students would use.  Do not include a trailing slash

$CFG->wwwroot  = 'http://' . $eduforge_prefix . '.lms.eduforge.org';


//=========================================================================
// 3. SERVER FILES LOCATION
//=========================================================================
// Next, specify the full OS directory path to this same location
// Make sure the upper/lower case is correct.  Some examples:
//
//    $CFG->dirroot = 'c:\FoxServ\www\moodle';    // Windows
//    $CFG->dirroot = '/var/www/html/moodle';    // Redhat Linux
//    $CFG->dirroot = '/home/example/www/moodle'; // Cpanel host

$CFG->dirroot  = '/home/lms/htdocs';


//=========================================================================
// 4. DATA FILES LOCATION
//=========================================================================
// Now you need a place where Moodle can save uploaded files.  This
// directory should be readable AND WRITEABLE by the web server user
// (usually 'nobody' or 'apache'), but it should not be accessible
// directly via the web.
//
// - On hosting systems you might need to make sure that your "group" has
//  no permissions at all, but that "others" have full permissions.
//
// - On Windows systems you might specify something like 'c:\moodledata'

$CFG->dataroot  = '/home/lms/var/' . $eduforge_prefix;


//=========================================================================
// 5. DATA FILES PERMISSIONS
//=========================================================================
// The following parameter sets the permissions of new directories
// created by Moodle within the data directory.  The format is in
// octal format (as used by the Unix utility chmod, for example).
// The default is usually OK, but you may want to change it to 0750
// if you are concerned about world-access to the files (you will need
// to make sure the web server process (eg Apache) can access the files.
// NOTE: the prefixed 0 is important, and don't use quotes.

$CFG->directorypermissions = 0777;


//=========================================================================
// 6. DIRECTORY LOCATION  (most people can just ignore this setting)
//=========================================================================
// A very few webhosts use /admin as a special URL for you to access a
// control panel or something.  Unfortunately this conflicts with the
// standard location for the Moodle admin pages.  You can fix this by
// renaming the admin directory in your installation, and putting that
// new name here.  eg "moodleadmin".  This will fix admin links in Moodle.

$CFG->admin = 'admin';


//=========================================================================
// 7. OTHER MISCELLANEOUS SETTINGS (ignore these for new installations)
//=========================================================================
//
// Prevent users from updating their profile images
//      $CFG->disableuserimages = true; 
//
// Prevent scheduled backups from operating (and hide the GUI for them)
// Useful for webhost operators who have alternate methods of backups
//      $CFG->disablescheduledbackups = true;
//
// Restrict certain usernames from doing things that may mess up a site
// This is especially useful for demonstration teacher accounts
//      $CFG->restrictusers = 'teacher,fred,jim';
//
// Turning this on will make Moodle filter more than usual, including
// forum subjects, activity names and so on (in ADDITION to the normal
// texts like forum postings, journals etc).  This is mostly only useful
// when using the multilang filter.  This feature may not be complete.
//      $CFG->filterall = true;
//
// Setting this to true will enable admins to edit any post at any time
//      $CFG->admineditalways = true;
//
// Setting this to true will force a non-guest login to see the user pages
// eg the teachers linked from course descriptions or site news
//      $CFG->forceloginforprofiles
//
// This setting will put Moodle in Unicode mode.  It's very new and
// most likely doesn't work yet.  THIS IS FOR DEVELOPERS ONLY, IT IS
// NOT RECOMMENDED FOR PRODUCTION SITES
//      $CFG->unicode = true;


//=========================================================================
// ALL DONE!  To continue installation, visit your main page with a browser
//=========================================================================

// Allow file overrides for eduforge
if (file_exists("$CFG->dirroot/config_" . $eduforge_prefix . ".php"))  {      // Do not edit
include_once("$CFG->dirroot/config_" . $eduforge_prefix . ".php");
}

if (file_exists("$CFG->dirroot/lib/setup.php"))  {      // Do not edit
    include_once("$CFG->dirroot/lib/setup.php");
} else {
    if ($CFG->dirroot == dirname(__FILE__)) {
        echo "<p>Could not find this file: $CFG->dirroot/lib/setup.php</p>";
        echo "<p>Are you sure all your files have been uploaded?</p>";
    } else {
        echo "<p>Error detected in config.php</p>";
        echo "<p>Error in: \$CFG->dirroot = '$CFG->dirroot';</p>";
        echo "<p>Try this: \$CFG->dirroot = '".dirname(__FILE__)."';</p>";
    }
    die;
}
// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,
// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.
?>

And this is how I run cron (from /etc/cron.d/lms_eduforge) -- it guesses the virtualhosts (which are actually aliases on one vhost):
## Every five minutes, scan 050_lms_eduforge_org.conf, figure out what are the relevant virtualhosts, and run admin/cron.php for each.
## the log is saved in /home/lms/var/cron.log with good timestamps.
*/5 * * * *    www-data        ( echo [`date`] Running admin/cron.php for all LMS instances ; /usr/bin/nice /usr/bin/perl -ne 'm/^\s*ServerAlias (\w+.lms.eduforge.org)\W/i &&  print "$1\n"'  /etc/apache/conf.d/050_lms_eduforge_org.conf  | /usr/bin/xargs --verbose -l -iVHOST /bin/bash -c "cd /home/lms/htdocs/admin/; HTTP_HOST=VHOST /usr/bin/php /home/lms/htdocs/admin/cron.php" 2>&1 )  >> /home/lms/var/cron.log

And this is the vhost entry, which is included in apache's config

<VirtualHost *:80>
        ServerName lms.eduforge.org

        # Add one ServerAlias entry per hosted LMS
        # The server alias is expected to take the form of
        # $prefix.lms.eduforge.org
        # The config file /home/lms/htdocs/config.php
        # overrides values on a per-serveralias basis,
        # the overrides must be placed in /home/lms/htdocs/config_$prefix.php
        # martin@catalyst.net.nz
        ServerAlias nmit.lms.eduforge.org
        # SEPARATE CODEBASE FOR OP # ServerAlias op.lms.eduforge.org
        ServerAlias tpp.lms.eduforge.org
        ServerAlias ucol.lms.eduforge.org
        #NEWALIAS#

        ## After you have added the ServerAlias, create dir /home/lms/var/$prefix
        ## owned by www-data.www-data . After that, you should be able to
        ## hit http://$prefix.lms.eduforge.org/ and complete the process
        ##
        ## If you want a special template, go to /home/lms/htdoc/theme/ ,
        ## and clone/modify an existing theme. It's simple.
        ##
        ## Cronjobs for all instaces of Moodle from this file
        ## are handled by /etc/cron.d/lms_eduforge_org
        ## DO NOT RENAME THIS FILE OR CHANGE THE STYLE OF IT
        ## WITHOUT CHECKING THE CRONJOB
        ##
        ## martin@catalyst.net.nz

        DocumentRoot /home/lms/htdocs
        CustomLog /var/log/apache/lms_access.log full
        ErrorLog  /var/log/apache/lms_error.log

        DirectoryIndex index.php index.html index.htm

        # nail down the PHP settings Moodle wants
        php_value magic_quotes_gpc        1 
        php_value magic_quotes_runtime    0
        php_value file_uploads            1
        php_value session.auto_start      0
        php_value session.bug_compat_warn  0

        # Apache and PHP settings for Uploads
        LimitRequestBody 0
        php_value upload_max_filesize 8M
        php_value post_max_size      8M
</VirtualHost>

 
Average of ratings: Useful (4)
Picture of Tony Hursh
Re: Run multiple instances of Moodle without duplicating base code?
 
Thanks, Martin! I'll dig into that code and give it a shot.
 
Average of ratings: -
Picture of Pieterjan Heyse
Re: Run multiple instances of Moodle without duplicating base code?
 
Martin, I used your trick to install our moodle 7 times, but have you got a trick to edit/update all the moodle installations at once ?

I'm editing the environment's descriptions and backup schemes, but I have to do this 7 times. Isn't there any more practical way ?
 
Average of ratings: -
Picture of Pieterjan Heyse
Re: Run multiple instances of Moodle without duplicating base code?
 
Ok, for now I have created a script in wich I can paste my moodle URL and it converts that url to the urls needed for the 7 sites to get in the right screen. this eases the pain, but it's definately not a very clean solution.
Will there ever be support in moodle for this kind of installation ?
 
Average of ratings: -
Picture of Thom Stricklin
Re: Run multiple instances of Moodle without duplicating base code?
 
I think your best bet would be to write a cron script that uses PHP/SQL to push copies of resources from one install to others...  But that's a somewhat uneducated guess, and heaven knows how you'd keep track of deleted resources, votes, quiz results, etc.  Quite an undertaking.

Here's a thought: if your installations are going to have much the same content, why not wait for the oft-referred Repository Module, then just set up multiple courses as opposed to multiple installs?
 
Average of ratings: -
Picture of So SoSo
Re: Run multiple instances of Moodle without duplicating base code?
 

hi
i did so far:
1. made the simple moodle test installation in soso.ch root with a with mysql db -> all works fine! then i deinstalled/deleted all.

2. now i want to built up a "common code" configuration with:
- typo.cw.soso.ch
- playg.cw.soso.ch

3. unzipped moodle15 to
/usr/locale/home/cw/htdocs (is the root with install.php ....)

4. going thru the special config.php given i this thread.
made changes in the settings. copied the file to the server.

5. mysql setup as needed with a db cwtypo.

6. in ie typing "http://typo.cw.soso.ch"
-> i'm getting the following screens, all with no errors
Copyright Statement
Home » Setting up database
Home » Current version
Home » Current release information
Variables ( click on save changes )
Home » Setting up module tables

on the last screen above -> there is no error statement, but nothing happen at the end. the browser shows http://typo.cw.soso.ch/admin/index.php in the adressbar.

if i refresh http://typo.cw.soso.ch/moodleadmin/index.php then a white blank page is shown, no error message.

Q:
- any hint?
- shoud i execute install.php in advance?

many thanks
soso

(Edited by Helen Foster by request of poster - original submission Monday, 1 August 2005, 03:13 PM)

 
Average of ratings: -
Picture of So SoSo
Re: Run multiple instances of Moodle without duplicating base code?
 

hi
the problem is solved.

thanks
ueli

 
Average of ratings: -
Picture of fevzi gungor
Re: Run multiple instances of Moodle without duplicating base code?
 
Can u post what was the cause and solution?
 
Average of ratings: -
Picture of Anil Sharma
Re: Run multiple instances of Moodle without duplicating base code?
 
Is there a way of doing this without using subdomains ? my present moodle installation is is www.kompz.com/skool . I want to use the same files installed there to also run another installtion at www.kompz.com also. Is that possible ?
 
Average of ratings: -
Picture of fevzi gungor
Re: Run multiple instances of Moodle without duplicating base code?
 
Of course there is a constraint that you do not do two different moodle installations? 
 
Average of ratings: -
Picture of Gavin McCullagh
Re: Run multiple instances of Moodle without duplicating base code?
 

What is the benefit of using the same database again rather than creating a second database?  Is this just to better fit hosting provider limitations?

Gavin
 
Average of ratings: -
Picture of fevzi gungor
Re: Run multiple instances of Moodle without duplicating base code?
 
I didnt see any advantages so i did my installation as different databases.
 
Average of ratings: -
Picture of lisa wright
Re: Run multiple instances of Moodle without duplicating base code?
 
Hi,

I noticed this was written in 2004.  Are these steps/files still accurate with the current version? 

Thanks
 
Average of ratings: -
Picture of Pieterjan Heyse
Re: Run multiple instances of Moodle without duplicating base code?
 
Yes, it is. I am running this kind of setup.
 
Average of ratings: -
Picture of lisa wright
Re: Run multiple instances of Moodle without duplicating base code?
 
I already have one instance of moodle installed and wish to add another.  I have altered config.php to refer to a separate database and dataroot depending on the URL accessed. 

Now, could someone tell me how to go about setting up the second set of database tables?  Install.php dies because I already have a config file. 

Also, could someone explain to me the purpose of the new code at the end of the config?

// Allow file overrides for eduforge
if (file_exists("$CFG->dirroot/config_" . $eduforge_prefix . ".php"))  {      // Do not edit
include_once("$CFG->dirroot/config_" . $eduforge_prefix . ".php");
}

if (file_exists("$CFG->dirroot/lib/setup.php"))  {      // Do not edit
    include_once("$CFG->dirroot/lib/setup.php");
} else {
    if ($CFG->dirroot == dirname(__FILE__)) {
        echo "<p>Could not find this file: $CFG->dirroot/lib/setup.php</p>";
        echo "<p>Are you sure all your files have been uploaded?</p>";
    } else {
        echo "<p>Error detected in config.php</p>";
        echo "<p>Error in: \$CFG->dirroot = '$CFG->dirroot';</p>";
        echo "<p>Try this: \$CFG->dirroot = '".dirname(__FILE__)."';</p>";
    }
    die;
}
// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,
// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.
?>

It seems to replace this: 

require_once("$CFG->dirroot/lib/setup.php");


Thanks!

 
Average of ratings: -
Picture of lisa wright
Re: Run multiple instances of Moodle without duplicating base code?
 
Okay I have resolved the problem of setting up the new db tables -- I just installed an entire new instance and then deleted the new directory.

I am still unclear on the code above -- mostly as to why the config file is including another config file.  If anyone can explain it to me that would be super smile
 
Average of ratings: -
Picture of lisa wright
Re: Run multiple instances of Moodle without duplicating base code?
 
Okay I get it. It's to override the config file, clearly.
 
Average of ratings: -
Picture of Ashutosh Bajpay
Re: Run multiple instances of Moodle without duplicating base code?
 

Hi Lisa

I know that I am replying to very old post. But I want to know had to completed this task. I mean creating multiple instances of moodle using subdomains. I have some question below please assist me...

1. Is it possible to do it without using subdomain I mean if I can do it in my local machine using local server?

2. If you have done it anyway please assist me the configuration steps in doing that.

Thank You. 

 
Average of ratings: -
Picture of Andreas Stoeffer
Re: Run multiple instances of Moodle without duplicating base code?
 
Hallo Martin,
I'm using your Script, to have multiple instances of Moodle.
It works, but I have two Problems:

1. With Cookies. If I use the Script as config.php the part of the Moodle Session Id is not sent and I cannot Login. (With the normal config.php, shipped with moodle, are no problems.)
2. In Firefox the Moolde Layout crashed. In Internet Explorer and Opera everything ist fine.

For any ideas from the Community, thank's a lot.

Andreas
 
Average of ratings: -
In Office
Re: Run multiple instances of Moodle without duplicating base code?
 
I also want to run multiple moodle installations using the same trick that of your's, but i am not that much skilled in the programming area. So please tell me what changes should i make into my config.php file to obtain the same.

Following are the code segments from your post:
What changes i should do in these code segments to achieve my objective.

$eduforge_prefix = $_SERVER['HTTP_HOST'];
if (isset($_ENV['HTTP_HOST'])){ // this is to support cronjobs on a per-host basis
$eduforge_prefix = $_ENV['HTTP_HOST'];
}
$eduforge_prefix = explode('.', $eduforge_prefix);
$eduforge_prefix = $eduforge_prefix[0];
$eduforge_prefix = preg_replace("/\W/", "", $eduforge_prefix);

// if there wasn't a prefix redirect to eduforge
if($eduforge_prefix == 'lms' || $eduforge_prefix=='') { //
header("Location: http://eduforge.org/");
exit;
}

and in this

// Allow file overrides for eduforge
if (file_exists("$CFG->dirroot/config_" . $eduforge_prefix . ".php")) { // Do not edit
include_once("$CFG->dirroot/config_" . $eduforge_prefix . ".php");
}

if (file_exists("$CFG->dirroot/lib/setup.php")) { // Do not edit
include_once("$CFG->dirroot/lib/setup.php");
} else {
if ($CFG->dirroot == dirname(__FILE__)) {
echo "<p>Could not find this file: $CFG->dirroot/lib/setup.php</p>";
echo "<p>Are you sure all your files have been uploaded?</p>";
} else {
echo "<p>Error detected in config.php</p>";
echo "<p>Error in: \$CFG->dirroot = '$CFG->dirroot';</p>";
echo "<p>Try this: \$CFG->dirroot = '".dirname(__FILE__)."';</p>";
}
die;
}



My config.php file is as shown below:
My moodle site is resided on the stand alone system.
<?php /// Moodle Configuration File

unset($CFG);

$CFG->dbtype = 'mysql';
$CFG->dbhost = 'XXXX';
$CFG->dbname = 'XXXX';
$CFG->dbuser = 'XXXX';
$CFG->dbpass = 'XXXXX';
$CFG->dbpersist = false;
$CFG->prefix = 'mdl_';
$CFG->wwwroot = 'http://localhost/moodle';
$CFG->dirroot = 'XXXX';
$CFG->dataroot = 'XXXXX';
$CFG->admin = 'XXXX';

$CFG->directorypermissions = 00777;

require_once("$CFG->dirroot/lib/setup.php");

// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,
// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.
?>

you can specify changes directly in the code.
I am using Moodle 1.8.2+

I can't able to understand the meaning of following line in your code what should it do: $eduforge_prefix = preg_replace("/\W/", "", $eduforge_prefix);


Thank you in advance.
Abhijit
 
Average of ratings: -
Picture of Richard Enison
Re: Run multiple instances of Moodle without duplicating base code?
 
AH,

It should delete all characters that are not alphanumeric (including underscore) in the value of the variable $eduforge_prefix.

RLE
 
Average of ratings: -
In Office
Re: Run multiple instances of Moodle without duplicating base code?
 
Thank you Richard for your help.

Richard, can you please tell me what changes I have to do in my config file to run multiple sites using that single file, I have given the structure of my config.php file in above post.

I am running my Moodle site on localhost(Apache) on stant alone machine.
I am running Moodle 1.8.2+

Thanks in advance!

Abhijit
 
Average of ratings: -
Picture of Richard Enison
Re: Run multiple instances of Moodle without duplicating base code?
 
AH,

It depends on a number of things. ML's setup is based on the fact that
  1. his web sites are separate subdomains of lms.eduforge.org (such as moodle1.lms.eduforge.org, moodle2.lms.eduforge.org, etc.), and that he has a main site eduforge.org, as well as an alias for it called lms.eduforge.org, which are separate from all the moodle sites. Do you plan to have subdomains? Or you could use a common web site with different subdirectories, such as http://localhost/moodle1, http://localhost/moodle2, etc.
  2. he has a single database common to all the Moodle sites; every table is associated with a particular Moodle instance by its table prefix, which is the subdomain prefix (e.g., moodle1). You might want to have separate databases, or even separate database hosts.
  3. he has separate data directories for the different instances of Moodle. That's probably a good idea.
  4. he has made provision for optional extra config files so that any particular variable in config.php can be overridden for a particular instance of Moodle.
  5. he has a complicated cron command that seems to use perl and a Linux (?) utility I never heard of called nice and frankly I don't fully understand it.
Bottom line: just because I know what the preg_replace function does doesn't mean I know everything!

RLE
 
Average of ratings: -
In Office
Re: Run multiple instances of Moodle without duplicating base code?
 
Thank you Richard for explaining. You guessed it clearly that I want to use a common web site with different subdirectories, such as http://localhost/moodle1, http://localhost/moodle2, etc. with separate databases and separate data directories for each site.

Also that cron command is very complex to understand for me.

If you get any information related to it then please forward its pointer to me.

Thank you again. Abhijit
 
Average of ratings: -
Picture of Richard Enison
Re: Run multiple instances of Moodle without duplicating base code?
 
AH,

That complicates things, in a way that I didn't think of when I suggested using different subdirectories, because the subdirectory that the URL points to normally is where the base code is rooted. But we want to have the base code all in one place, so there has to be at least one file in the subdirectories moodle1, moodle2 etc. that redirects to the common code directory (perhaps the parent directory, perhaps some subdirectory of it called moodlecode or whatever) in such a way that config.php "knows" where it came from. We could use an HTTP variable in PHP that tells you where you were referred from ($_SERVER[HTTP_REFERER]), but according to the PHP manual, it is set by the browser and not all browser set it, so it can't be trusted.

I could write an index.php script to put in the subdirectories moodle1, etc. that would find out where they are using __FILE__ and pass that info on to the index.php script in the common directory. But then what if someone wants to directly address a script in the root such as install.php? If they type http://localhost/moodle3/install.php, they would get a "File not found" error (or equivalent). So maybe we need to put an install.php script in each subdirectory also?

Finally, what's worse is what if someone wants to directly access a script or other file buried within the directory tree, like http://localhost/moodle4/admin/replace.php? That's just one example.

How many of these things do you want to be able to handle?

RLE
 
Average of ratings: -
In Office
Re: Run multiple instances of Moodle without duplicating base code?
 
Richard, frankly speaking i am not able to handle a single thing you have suggested, all are like bouncer above my head. So better way i will try to do this with suggestion from one moodler that for each site i will create duplicate copy of moodle scripts and separate config.php for each site.

Any way thank you very much Richard for helping me.

Abhijit
 
Average of ratings: -
Picture of Jim Bennett
Re: Run multiple instances of Moodle without duplicating base code?
 

Hello all,

I know this is an old post, but I need to do a similar thing.  I'm fairly new to Moodle, just having finished playing with it for a few months to do some learning/prototyping.

We have 50 schools that we want to create sites for.  We would like to have each school access it's Moodle site using xxx.vc.stpaul.sk.ca, where xxx is the 3 character code to identify the school, and use just the one Moodle installed code-base to handle it.  We would also like to have each school sit on it's own database (Moodle_XXX, where XXX is the school code).

We're running this system on Windows Server 2008 R2, IIS 7 and the database resides on SQL Server 2008 R2.

I was wondering if anyone has done this configuration before?  This post nicely covers setting it up in Apache and sitting on one database, but I would like to acheive our requirements if at all possible.

Thanks in advance!

 
Average of ratings: -
Picture of Jim Bennett
Re: Run multiple instances of Moodle without duplicating base code?
 

I've figured out how to do it, though there may be more elegant solutions ... I'll post what I've done here in case it helps someone else out in future ...

I  created a script to create each database, and then systematically navigate to each schools unique url which just points to my main Moodle install using a wildcard DNS. This launches the Moodle configuration. Once the configuration is complete, I move the config file to another folder and rename it using the school code (config_xxx.php).  I do this for each school, and at the end I create a config.php in my www root which gets the subdomain from the URL (which is the school code) and loads the porper config file.

labour intensive to create ... but it's working!  If someone has a simpler solution please post it!

Cheers!

 
Average of ratings: -
Picture of Piyush Pandey
Re: Run multiple instances of Moodle without duplicating base code?
 

Hi Jim, Can you please share this work done by you....

 

Waiting for your reply

 
Average of ratings: -
Picture of Daniel Neis Araujo
Re: Run multiple instances of Moodle without duplicating base code?
Core developersParticularly helpful MoodlersPlugin developersTranslators

Hello,

 

you may be interested in Multitenant support, that is planned to 2.3 : http://docs.moodle.org/dev/Multitenant_support

 

HTH,

Daniel

 
Average of ratings: -
Picture of Konrad Lorinczi
Re: Run multiple instances of Moodle without duplicating base code?
 

I'm glad to hear the Multitenant support is under development, but I think the "multiple instances of Moodle without duplicating base code" problem might be solved easier.

 

If the config.cfg file is modified to be a dispatcher script, which loads the correct /another/moodle/config.cfg file, depending on the used domain name or by using mod_rewrite Apache module to distinguish between the different databases.

IMHO this could be a working and easy solution of Multiple Moodle instances on one installation.

 

 
Average of ratings: -
Rosario playing soccer
Re: Run multiple instances of Moodle without duplicating base code?
Plugin developers

Jim, I know that Austria is doing this nation wide. I contacted them some years ago as I was planning the same for our universtities, which finally decided to run only ONE Moodle-Instance but with different categories for every university with their own themes.

Look them up in the moodle biggest sites list and aks them if they would like to share their scripts to install and update their multiple Moodle instances.

Rosario

 
Average of ratings: -
Picture of Arvind Dubey
Re: Run multiple instances of Moodle without duplicating base code?
 

Hi guys,

I am new to creating multy instance of single moodle code base. I configured Virtual host and config.php and all instances are running fine. Now I am trying to run cron.php for each virtual intsance of moodle. Please let me clarify, How I can run cron job for cron.php of each instance of moodle created as virualy, I am not able to configure it. Please help me to configure cron.php for each moodle instance.

You have given a very nice example but I am not getting "cron setting" part. Please make it clear.

Thanks in advance.

 
Average of ratings: -
Picture of Rob Barreca
Re: Run multiple instances of Moodle without duplicating base code?
 
Anybody have success running the Moodle Chat Daemon under this type of multiple installations?  Everything else in my duplicated Moodle installations works fine, but I'm trying to figure out what to do to mod/chat/chatd.php as it loads a dummy config file.  Any thoughts?
 
Average of ratings: -
Martin Langhoff - Sailing
Re: Run multiple instances of Moodle without duplicating base code?
 
You'll have to do additional trickery and magic for chatd, it doesn't work out-of-the box, and it probably needs some serious surgery for that sad

 
Average of ratings: -
Picture of Nicolas Martignoni
Re: Run multiple instances of Moodle without duplicating base code?
Core developersDocumentation writersParticularly helpful MoodlersPlugin developersTestersTranslators
See and evagelize wink bug #1946
 
Average of ratings: -
Picture of Rob Barreca
Re: Run multiple instances of Moodle without duplicating base code?
 
Voted for it. But for the time being I will try to run a daemon for each Moodle installation. So, if I'm running them all off the same server, I should just use a different port for each daemon, right? So 9111 for site1.com, 9112 for site2.com, etc.?  And I'll modify chatd.php to take a argument for which config to use, so when my server starts I'll run...

# chatd.php?config=site1.com
# chatd.php?config=site2.com (obviously not syntactically correct)

Somebody let me know if that sounds like the way to go.
 
Average of ratings: -
Picture of Krishna Moorthy
Re: Run multiple instances of Moodle without duplicating base code?
 
If anyone found the solution for chatd problem, let us know. We would like to hear more about it
 
Average of ratings: -
Picture of chris nikolaidis
Re: Run multiple instances of Moodle without duplicating base code?
 
Hello,
I am wondering if there is a way to have the same SCORM content, or other resource, available for multiple Moodle instances with no need of duplication.
This could be helpful not only for hard disk space economy but for content update purposes (if I want to install a new version of SCORM material I would prefer to do it once).
Thanks in advance, and excuse me if the answer is obvious (I am a moodle newcomer).
 
Average of ratings: -
Picture of Helen Foster
Re: Run multiple instances of Moodle without duplicating base code?
Core developersDocumentation writersMoodle HQParticularly helpful MoodlersPlugin developersTestersTranslators
Hi Chris,

The repository API planned for Moodle 1.7 (expected August 2006) will most likely provide the solution you require. In the meantime, if SCORM tracking data is not needed, you may wish to consider using the Object module. Please check the discussion New module: Object for further details.
 
Average of ratings: -
Picture of chris nikolaidis
Re: Run multiple instances of Moodle without duplicating base code?
 

Thanks Helen,

I will test the Object module.

 
Average of ratings: -
Picture of Ralph Owens
Re: Run multiple instances of Moodle without duplicating base code?
 

I am a Moodle newbie and want to have two (or more) seperate sites.  One for course development and one as a production site.  We were thinking of two separate servers for the two sites, but would rather have just one.

This thread looks like it answers many of our questions, but the last post was on Moodle 1.7.  We are using 1.9.  Are these answers, templates, etc still valid?

-Reo

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Run multiple instances of Moodle without duplicating base code?
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers
The answer should still be valid.

However, I think putting development and production on the same server would be a big mistake. Your initial instinct to keep the two separate is the right one. You will screw up your development server at some point, at which point you will just want to blow it away and re-install. On the other hand, you want to minimise what is running on the production server, so there is the minimal number of things that could go wrong there.

 
Average of ratings: -
Picture of Ralph Owens
Re: Run multiple instances of Moodle without duplicating base code?
 

Thanks, Tim.

In general, I agree with your comments.

However, my goal is not to develop Moodle code, but to develop Moodle courses in a non-production environment.  Then when the course is complete and approved, I'll move it over to the production environment.  I'm thinking that a course-development-only site should be able to safely co-exist with a production site.  Part of my reasoning is that if they use the same identical code then I know the course will work when I move it to production.

But being a newbie, I'll listen to the voice of experience.  Perhaps, even course development will occasionally screw up everything and I'll have to blow it away and risk the production environment.

-reo

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Run multiple instances of Moodle without duplicating base code?
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers
Ah, that is different. I was thinking about a developer's dev site.

You could also consider just a hidden category in your production site - that will make the course easier to move.

However, there are still advantages to a completely separate dev server. For example, you will need to test upgrades to the Moodle code, or operating system patches, before you update your production site. Or, you may wish to trial a new module or plugin.


 
Average of ratings: -
Picture of Ralph Owens
Re: Run multiple instances of Moodle without duplicating base code?
 
OK.  Good.  Thx again, Tim.  I appreciate the insights.  -reo
 
Average of ratings: -
Picture of Navneet Dixit
Re: Run multiple instances of Moodle without duplicating base code?
 

Hi,

I need a script which create a new moodle instalation every time a user need. User will enter the folder name and a seprate moodle instalation with entered name and diffrent database.

Please help.

 

Thanks

Navneet

 
Average of ratings: -
Picture of Thomas van den Heuvel
Re: Run multiple instances of Moodle without duplicating base code?
 

We run multiple instances on both a (single) Moodle 1.7 and 2.1 codebase. We call these instances by separate hostnames. The only thing we need to change in the code is create a switch-statement on the hostname in the root config.php file, and put everything that is instance-dependant (such as $CFG->dbname and $CFG->dataroot which are basically the only two values that need to change) within a host-case. In this way each instance has their own database and datadirectory, so this provides a real clean way of separating instances and minimal code-changes.

To prepare for this hostname-switch-construction you need to move all the hostname dependant code within the switch statement:

...
switch ($_SERVER['HTTP_HOST']) {
case 'instance1.yourdomain.com':
$CFG->dbname = '...';
$CFG->dataroot = '...';
// and what else you want to configure here
// ...
break;
case 'instance2.yourdomain.com':
$CFG->dbname = '...';
$CFG->dataroot = '...';
// and what else you want to configure here
// ...
break;
case 'some.completelyother.org':
  $CFG->dbname = '...';
$CFG->dataroot = '...';
// and what else you want to configure here
// ...
break;
default:
die('domain not configured in config.php');
}
...

The above example is for live environments, for (local) development you probably use a different config file.

Creating a new (live) instance (at least in Moodle 2.1) comes down to this (assuming you have a (sub)domain configured):

- make a new case for this (sub)domain
- create a database (with the same host and username as the other instance-databases) and new datadirectory and configure these in the new case

Upon calling this new (sub)domain (remember: the database and datadirectory are still completely empty) this database and datadirectory will be (seem to be) populated automagically. Installation of new instance: done!

 
Average of ratings: Useful (4)
Picture of Đinh Lư Giang
Trả lời: Re: Run multiple instances of Moodle without duplicating base code?
 

Dear Thomas (if I may)

I am not good at coding, so after reading your so interesting post, please allow me to imagine the steps for the whole installation:

1. Install Moodle code in the the Root directory

2. Create different database, different subdomains, different moodledata directories

3. Change the config.php of the Root directory

For the step 3, could you tell exactly where the "hostname dependant code" should be inserted, and what originally in the config. php needs to be removed? Also, can each instance has a completely different theme, site forum, site frontpage. This question comes from what we are looking for solution: We are installing Moodle for a univ. with many departments. We want to have forum for each department. The old idea for us was to assign each department a category, but customization of the category was not enough to make it a "virtual office of the department" when category forum (for only users in that category and sub-categories" remain unsolved.

Please advise. Thanks a lot

Giang

 

 

 
Average of ratings: -
Picture of Thomas van den Heuvel
Re: Trả lời: Re: Run multiple instances of Moodle without duplicating base code?
 

Hello,

Depending on your setup you need to move / replace several $CFG settings in your config.php file. If you have one database-server, and you connect to all the databases in the same way, you do not have to move $CFG->dbhost, $CFG->dbuser or $CFG->dbpass because they all will be the same for the different instances, they just need a (one) correct value.

Assuming you always connect to one database-server with the same username/password combination, the only things that differs between the instances is the database-name (CFG->dbname), the website location ($CFG->wwwroot - I forgot this one earlier lol) and the data files location ($CFG->dataroot).

So, taking config-dist.php of the official 2.2.1 release as an example:
- configure $CFG->dbtype, $CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->prefix, $CFG->dboptions to your preferred / required settings
- remove $CFG->dbname from line 44, we will set a specific database in the switch-statement
- remove $CFG->wwwroot from line 97, we will set a specific wwwroot in the switch-statement
- remove $CFG->dataroot from line 111, we will set a specific dataroot in the switch-statement

It does not really matter where you place the switch-statement, as long as you do it after $CFG is created (line 32) so you can place it right at the top of your code, for example at the end of the "1. DATABASE SETUP" configuration part. Assuming you connect to one database with the same username/password setup, your switch statement could look like this:

switch ($_SERVER['HTTP_HOST']) {
// 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.domain.com'; // 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.domain.com'; // no trailing slash
$CFG->dataroot = '/path/to/sub2data/'; // depends on where you put your datadir
break;
// et cetera
default:
die('hostname not found in config.php');
}

If you want more finegrained control per instance, you move more $CFG variables from the "global scope" into the switch-statement (the "domain specific scope"). The above should give you a minimal set.

Because all the instances have separate databases and data-directories, each instance can have its own theme, forum and front page. They all run independent from eachother, they only share the same code, which is something you have to take into account when changing code - it will affect all the instances, those changes are "global".

I hope this post was useful.

 
Average of ratings: Useful (2)
Picture of Đinh Lư Giang
Trả lời: Re: Trả lời: Re: Run multiple instances of Moodle without duplicating base code?
 

Dear Thomas,

Thanks a lot for your detailed explanations. I think Moodle developers should be interested in this very useful solution for the so called multipl instances of Moodle installation.

Have a good time

Giang

 
Average of ratings: -
Picture of Doug Rinker
Re: Trả lời: Re: Run multiple instances of Moodle without duplicating base code?
 

I am currently considering a shift to multi-tenant capability (in Moodle 2.3) using the single codebase / multi-config approach.  I found Thomas' postings on this topic this past year to be the most helpful in seeing a fairly clean path to doing this with a switch statement in a single config file... so, I'm inclined to follow that approach. 

For Thomas or others experienced in doing this, I'm posing a few questions as I've thought through this further, and would like to benefit from the experience and thoughts of others on these questions:

1) It would seem that running crons would also require a special modification of cron.php as well, but I have not seen anyone discuss this.. It would seem that the cron function would need to be run separately for each moodle instance, and would need to "require" the inclusion of the config.php with the correct statements for each instance. Wondering how anyone has handled this and if there is more to do other than just require the correct config.php within each instance of the cron run? Also, running cron from CLI has no knowledge or concern with the various unique host domains that identify each instance, so it would seem that Thomas' switch statement approach would not work for the cron execution instances (seems you would need a separate config.php/cron.php coded for each instance if running a cron via CLI for each instance?). My hosting service does not support the url/browser-based approach to running crons (for security reasons), otherwise that might work using the switch method (?)


2) Has anyone done something special to segregate custom themes so that they are not visible to the tenants on other instances?

3) Would I be correct in thinking that since there is a separate DB and moodledata for each site instance, each instance would essentially start out as a fresh install with all the default admin settings that would exist in a new install, and that essentially all admin settings (aside from physical plugin/theme files existing or not) would be independent from one site instance to the next?

4) Related to item 3, after setting up a new empty DB and config.php mods for a new instance, how do things get initialized?... Does the normal install/setup process run automatically after a new instance is setup simply because an empty database is detected just like on a true initial install of the codebase?

5) Finally, would appreciate any thoughts on lessons learned to date on this overall approach and on issues that one should be aware of... Interested in the ongoing motivations people have for this approach and whether you have found the trade-offs vs separate codebases to be worthwhile over the long term. 

Thanks in advance for any insights that Thomas or others can provide on these questions.

- Doug

 

 
Average of ratings: -
Picture of connie swiderski
Re: Trả lời: Re: Run multiple instances of Moodle without duplicating base code?
 

Thomas,

I followed this and it works fantastic! My only problem now is the cron. it will run per each subdomain within the Notification but will not run as a cron task. Could you please share how I should set that up in order for all 4 subdomains to run their cron via the task scheduled?

Connie

 
Average of ratings: -
Picture of Igor Kopetschke
Re: Trả lời: Re: Run multiple instances of Moodle without duplicating base code?
 

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) {
// 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
}
$CFG->dirroot = '/var/www/html/main.moodle';

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.

 
Average of ratings: Useful (1)
Gareth J Barnard
Re: Run multiple instances of Moodle without duplicating base code?
Core developersParticularly helpful MoodlersPlugin developers

Dear Thomas,

I think this looks really elegant.  This issue was discussed at the February developer meeting - http://docs.moodle.org/dev/Developer_meeting_February_2012#Multi-tenancy - and has a tracker issue MDL-28946.

Cheers,

Gareth

 
Average of ratings: -
Picture of mart van der niet
Re: Run multiple instances of Moodle without duplicating base code?
 

Hi Thomas,


This seems a very easy way to handle multiple installations, but...

I have a base domain:

www.basedomain.nl


and a number of subdomains, one for each customer

cust1. basedomain.nl, cust2.basedomain.nl etc


The idea is that every customer sees his own adress in the browser, and each has its own favicon, other modifications (per customer theme) in the db, and the logo and link on the base of the frontpage selected with a swith statement in lib/outputrenders.php

Each customer should be able to invoke moodle with custN. basedomain.nl, which then should use the common codebase and per user a separate instance of the moodle db.

I changed the config.php in the root of a customersite (which has its own db):

$CFG->dbtype    = 'mysqli';
$CFG->dblibrary = 'native';
$CFG->dbhost    = 'hostname';
$CFG->dbname    = 'dbname_for_this_customer';
$CFG->dbuser    = 'common_user';
$CFG->dbpass    = 'common_pwd';
$CFG->prefix    = 'mdl_';
$CFG->dboptions = array (
  'dbpersist' => 0,
  'dbsocket' => 0,
);

$CFG->wwwroot   = 'http://www.commonroot.nl';
$CFG->dataroot  = '/path to moodledata/moodledata/customer1';

I get :

Warning: require_once(/home/users/prinqftp/idee-ict.prince2leren.nu/lib/setup.php) [function.require-once]: failed to open stream: No such file or directory in /home/users/prinqftp/idee-ict.prince2leren.nu/config.php on line 28

Fatal error: require_once() [function.require]: Failed opening required '/home/users/prinqftp/idee-ict.prince2leren.nu/lib/setup.php' (include_path='.:/usr/share/php') in /home/users/prinqftp/idee-ict.prince2leren.nu/config.php on line 28

 

Any idea how to work around this one??

 

Thanks in advance

 
Average of ratings: -
Picture of Jeff Rader
Re: Run multiple instances of Moodle without duplicating base code?
 

Anyone got any ideas on why I can log into one instance of Moodle, but the other one says I don't have cookies enabled on my browser?  I'm using different subdomains 2 sites.

 
Average of ratings: -
Picture of Hubert Chathi
Re: Run multiple instances of Moodle without duplicating base code?
Plugin developers

WARNING:

Running multiple instances of Moodle from a single copy of code sounds neat, but depending on your situation, it may cause more problems than it solves.  You should be aware of the implications of sharing the same copy of code, such as:

  • all instances will need to be upgraded at the same time: Upgrading (especially from one major version to another) can be a very long process.
    • Dumping the new code onto the server, and hitting the upgrade button can take quite a while.  Once you dump in the new code, sites may not work properly until they are upgraded.  Are you sure you want to upgrade 50 sites at the same time?
    • Even before you dump the new node onto the server, upgrading requires investigation work, making sure that the upgrade won't break anything.  This may take a lot of time.  If you share one copy of the code, that means that you'll have to do this investigative work on all of your sites before any of them can be upgraded.
    • Upgrading also means that you need to make sure that all the plugins that you use are compatible with the new version, and that Moodle's behaviour hasn't changed in ways that break the way you are using it.  If, say, you have one site that uses a certain plugin that isn't compatible with the new version, but none of your other sites use that plugin, are you willing to hold off on upgrading the other sites until that one plugin is upgraded?  Or can you tell that one site: "tough luck, you'll have to do without the plugin"?
  • using a single copy of the code means, well, the code is the same.  If site1 needs a plugin, but site2 doesn't want (or breaks, or will be too slow) the plugin, what do you do?

You probably do not want to use a single copy of code if:

  • you are providing commercial support
  • have more than a handful of sites
  • your sites have very different needs
  • your sites are intended to be available long-term
 
Average of ratings: Useful (2)
Picture of Tomasz Muras
Re: Run multiple instances of Moodle without duplicating base code?
Core developersParticularly helpful MoodlersPlugin developersPlugins guardiansTranslators

I would second Hubert here. What would be an advantage of having a single copy of source code files? Saving few dozen megabytes of space per instance?

"Upgrading all sites at once" is not an argument - you still need to act on each Moodle being upgraded. On the other hand, it's one-liner in bash to copy directory into hunderds of directories - so you can get the same effect if you have separate source code files for each Moodle.

If you want to have several Moodles that use the same code, then you should use version control system to manage that + some deployment scripts if you want to create new Moodle sites easily.

Tomek

 
Average of ratings: -
Picture of Edmund Edgar
Re: Run multiple instances of Moodle without duplicating base code?
 

The way to get the best of both worlds here is to keep a single shared directory with the Moodle code of each version you manage then make a symlink to it for each site.

If you want to upgrade your sites one at a time, make a new directory for the new Moodle code and switch each symlink in turn, followed by running the migration for that site. Once they're all done you can delete the original code if you want to.

If you want to use different code for one or two sites (eg most people want the same thing, but one or two people want some exotic module), replace the symlink with a full copy of the code for just those sites.

 
Average of ratings: -
Picture of Olusegun Shodeinde
Re: Run multiple instances of Moodle without duplicating base code?
 

Hello, please I want you to advice/guide me. I have moodle installation version 1.9 and 2.2, the both are working fine with different databases, I want to combine the two databases to be one. so that when user register/login in any of the site, it will work in as single database not as two different database as before.

 I mean to combine only users details, so users would not have to register twice on my websites but with one registration to have access to both your websites.

Thank you

 
Average of ratings: -
Picture of Amarnauth Seegobin
Re: Run multiple instances of Moodle without duplicating base code?
 

External database authentication method may suit your needs..see http://docs.moodle.org/26/en/External_database_authentication

 
Average of ratings: -
Picture of Jez H
Re: Run multiple instances of Moodle without duplicating base code?
Particularly helpful MoodlersPlugin developers

Take a look at Mnet where users from one Moodle site can be authenticated in another, you can set that up without any additional code / database links:

http://docs.moodle.org/19/en/MNet

 
Average of ratings: -