Running multiple instance of MediaWiki on the Same Server using the Same Source Code?

Note: The content is written for the “MediaWiki Administrators’ tutorial guide” book readers. So you will find some reference of the book here. Ignore those references if you do not have the book. You can download the PDF at the bottom of the article.

Sometime it might require for you to setup multiple MediaWiki site on the same server using the same source code. The reason behind using the same code base for multiple wiki is easy to maintain the changes. It is always easier to maintain a single thing rather than instances of the same thing. In order to accomplish this task you have to follow few simple methods.

1. Use same database server and same database with different tables or

2. Use same database server but different database or

3. Use different database server.

Before narrating the steps for achieving your target to setup multiple wiki using same source code, you have to know what will be the required things to consider before installing multiple wiki in a single server. First of all you need to separate the database configuration and other configuration (the configuration variables in LocalSettings.php file) into different files or separate them to work properly. The next important thing is to separate upload directory so that multiple wiki do not conflict in common files. Most of the time multiple wiki are required for multilingual purpose and in multilingual site same content is shown but in different language. There is a fair possibility that two wiki can have same image file name in use. In such case one will replace another. In order to avoid such unwanted circumstances, it is always better to separate the image folder for each wiki installation. The last thing to consider is the extensions that you are using for the existing wiki. You can make a common extension file and place all the extension to that file so that all the wiki instances share the common extensions. Now let me show you the ways you can make it work:

Let’s make it work:

In chapter two of the book you have learned how to install MediaWiki at your server. You also learned the fact that you have to move the LocalSettings.php file in the root folder for the installation to work. Now here are steps to apply.

1. Rename your existing LocalSettings.php file to Wiki_one_settings.php or anything you want to.

2. Now open a browser window and type your URL location for the wiki. If your URL is then try to browse the .

3. You will be taken to the installation page same as described in chapter 2. You have to follow the same steps until the database configuration section. As you know you can choose the same database but different prefix for new installation or you can choose a new database name for the new installation or even choose a new server located in some other place for the new installation. Here is the place you have to enter the database information.

4. If you want to use the same database but different tables then we gave to add database table prefix in the colored region of the image. You can add any prefix for the new tables. If you wan to add new database then add database name in the database name field.

5. After putting all required information, click the install button to install new instance of MediaWiki. A new instance of the MediaWiki database has been added to the database server according to your chosen method and a new LocalSettings.php file is also created in the Config folder. Like you did in chapter two, you have to place this file in the root folder. But you have to play another little trick here. Since it is used for second wiki, we have to rename the file as Wiki_two_settings.php (or any name that you want to) and then you can place it in the root folder.

6. Now you have two settings file Wiki_one_settings.php and Wiki_two_settings.php but no LocalSettings.php file. So you have to create a file named LocalSettings.php. You can have two scenarios over here:

a. First of all you can have wikis are in different directories or sub domains linked to the same directory on our server

b. We have different domains that link to one directory on your server

For the first scenario we have to write the following code and save it as LocalSettings.php.

For the second scenario we have to write the following code and save it as LocalSettings.php

Now you run the wiki and see the different wiki using the same source code. If your site address is then browse and also . You will find the difference by yourself.

Note: To link the sub domains to the server, you might need to edit the configuration file of the server or change the DNS configuration of the site.


Setting Different Image directory:

If you want to set different upload directory for each wiki installation, you can do that too. Just define the upload directory on each of the LocalSettings.php file for each wiki. First you have to make sure that the file upload option is enabled. Then add the following line at the end of the LocalSettings.php file.

For example for the first wiki you have to write the following line

$wgUploadDirectory = “{$IP}/images”;

And for the second wiki you can use different directory

$wgUploadDirectory = “{$IP}second_/images”;

Now save the file and access the pages. We are all done with setting different image directory for each wiki.

Sharing common resources:

Sometime it might be required for you to share files and extensions for your wiki installation. For creating a shared directory we have to write the following lines from DefaultSettings.php to LocalSettings.php file for each LocalSettings.php file.

$wgUseSharedUploads = true;

$wgSharedUploadPath = ‘http://yourwikiname/images’;

$wgSharedUploadDirectory = ‘/(LOCALPATH)/Folder Name/images/’;

$wgHashedSharedUploadDirectory = true;

In order to share common extensions first you need to copy all the extensions inclusion to a common file. You can name the file anything you want to. Now include the common extension file in every LocalSettings.php file you have created. So if you need to add/remove any extension you just have to edit the common extension file not every settings file.

This way you can integrate multiple wiki using the same code base. You can play around with the LocalSettings.php file as you can put some kind of switching command instead of creating separate setting files. The way is shown and you can apply your knowledge for something better.

Note: if you are looking for more references then you can look at the following sites. They are very well explained.

[Download PDF]

22 thoughts on “Running multiple instance of MediaWiki on the Same Server using the Same Source Code?

  1. zezinho says:

    That’s a very nice tutorial of yours. But how about the maintenance scripts? How to make them choose the correct LocalSettings.php to perform a “deleteBatch.php” for example?

  2. dave says:

    Thanks for the step-by-step tutorial. I’m a php newbie. I have more than 2 sites running on the mediawiki codebase so i altered the LocalSettings.php file to a series of if/elseif statements. It didn’t seem to work with “===” so i changed to “==” and it worked. Not sure if i’m just using this operator wrong or what. Everything else worked perfectly.

  3. Dave says:


    nice tutorial!
    What if I my wikis need to be in different directories and different domains linked to one source code and one database?


  4. Kai says:

    This comment refers to the first scenario:

    You must create the symlink befor creating the new wiki. Use the symlink path for creating the new wiki. Otherwise the LocalSettings.php shown above will not work.

    Edit the LocalSettings.php of the new wiki. The $wgScriptPath variable must be set to the path of the Symlink, not the original mediawiki.

  5. Kai says:

    Setting Different Image directory:

    You additionally have to set the variable $wgUploadPath to the same directory as $wgUploadDirectory. Otherwise the uploaded files cannot be referenced.

  6. payo says:


    i have a question

    i am working with mediawiki-11 and i am working with multiples wikis.

    how i can share users between wikis?


  7. Stoneway says:

    Yes, I am also interested in having two wikis share a single user database. Using AD would be nice, but not an option right now.

  8. Michael says:

    I have the same question as zeninho.

    I have about 4000 pages in Twiki that I have converted to MW, but I want to break the twiki equivalent of namespaces into different MW instances (because I want to have separate categories and clean searches and user bases).

    I’m thinking that I will need to set the wiki_one_settings.php to LocalSettings.php, run my script, and then rename it back.

    Could we do something that detected that the script was being run from the command line and read an arg as the wiki to use?

    This is definitely something we’ll need to worry about when we upgrade a MW instance.

    Updating may be quite difficult. Can you discuss how you’d upgrade from one version to another in this scenario?

  9. Bob Morris says:

    I like this, and had in mind to simplify maintenance a little by dispatching using an map keyed by the name of the aliases in the apache.conf file on /etc/mediawiki with code in LocalSettings.php thus:

    “/cs11x/” => “LocalSettings_cs11x.php”,
    “/cs11xF08/” => “LocalSettings_cs11xF08.php”);

    #$wiki = strtolower($_SERVER[‘REQUEST_URI’]); //doesn’t work with this
    $wiki=’/cs639/’; //works with this
    $settings = $localSettings[$wiki];

    Everything works fine if I extract with an explicit string, as in the line marked
    //works with this
    But if I extract the string as in the line before, an odd failure happens, even though printing the value of $wiki at that point seems to give the same value. (Even with trim(…) in case I was missing hidden white space). The error reflected in the browser is below, but I would also note that judicious prints convinced me that in the error provoking case:
    – the correct subsidiary LocalSettings file is invoked
    – the chain of require_once files executed all the way down to the bottom of DefaultSettings.php, which seemed to be the last such file inclusion
    – the php include_path is the same in both cases
    – the behaviour is the same whether I invoke
    http://…./cs639 or http://…./cs639/

    The error seems to suggest that something is passing an empty string to require_once

    Fatal error: require_once() [function.require]: Failed opening required ” (include_path=’.:/usr/share/php:/usr/share/pear’) in /etc/mediawiki/LocalSettings.php on line 19

    Am I missing something simple, or is there a good reason you used constants in your dispatch?


  10. Dave says:


    thanks, I finally made this almost to work. Well, except for the “Skins” directory, that can not be shared?
    Does anybody know why?
    I use Wiki 1.13.x


  11. Dave says:

    Ok, I got this, had to define $wgStylePath in SettingsExtensions.php 🙂

    This works for me, different domains and everything except index.php is shared:

    Wikipool LocalSettings.php:

    switch ($_SERVER[“SERVER_NAME”])
    case “www.serverone.tld”:
    require_once “LocalSettings_1.php”;
    case “serverone.tld”:
    require_once “LocalSettings_1.php”;

    case “www.servertwo.tld”:
    require_once “LocalSettings_2.php”;
    case “servertwo.tld”:
    require_once “LocalSettings_2.php”;

    echo “This wiki is not available. Check configuration.”;

  12. Paul says:

    To get this to work, I had to use different values of $wgScriptPath for each wiki as I think Kai was suggesting AND create rewrite rules to map these to the single wiki source.

    So, in the individual LocalSettings files:
    $wgScriptPath = ‘wiki1src’;
    $wgArticlePath = ‘wiki1’;

    $wgScriptPath = ‘wiki2src’;
    $wgArticlePath = ‘wiki2’;

    & in .htaccess with the wiki src in the directory /w/
    RewriteRule ^wiki1src/(.*)$ /w/$1 [PT,L,QSA]
    RewriteRule ^wiki2src/(.*)$ /w/$1 [PT,L,QSA]

    + the usual:
    RewriteRule ^wiki1/(.*)$ /w/index.php?title=$1 [PT,L,QSA]
    RewriteRule ^wiki1/*$ wiki1/ [L,QSA]

    RewriteRule ^wiki2/(.*)$ /w/index.php?title=$1 [PT,L,QSA]
    RewriteRule ^wiki2/*$ wiki1/ [L,QSA]

    to create pretty urls.

  13. slowpoison says:

    You need to also set the MW_INSTALL_PATH variable in Wiki_one_settings.php and Wiki_two_settings.php to reflect the directory. At least, I’m having problems without these.

  14. Richard says:

    I meet one question. I want to run two different wikis at localhost. they use same port number and wiki content in same folder.

    what should I configure my localsettings.php file to start different wiki?

  15. Clinton Diruzzo says:

    Hello. I hope you dont mind me commenting on your blog. I wanted to let you know directly but I cannot find your contact info. I want to subscribe to your blog for updates but I am unable find your RSS subscription button. Please assist. Thanks.

  16. Pingback: Quora

Leave a Reply

Your email address will not be published. Required fields are marked *