Repeat step two and three above for each wiki you wish to create, creating a new LocalSettings.php file for each wiki (e.g., LocalSettings_anotherWiki.php, etc.)

If two or more separately installed wikis are to be merged to operate out of files of the main wiki, then after renaming and moving each of your LocalSettings.php files to the main wiki folder, change the variable $wgScriptPathManual:$wgScriptPath in each of the LocalSettings.php files to point to the main wiki's folder.

Create a LocalSettings.php file for your global settings, then select one from the two possibilities below:

If you have different (sub)domains that link to one directory on your server, use this:

<?php// Include common settings to all wikis before this line (eg. database configuration)switch($_SERVER['SERVER_NAME']){case'shoopz.com':require_once'LocalSettings_shoopz_com.php';break;case'help.shoopz.com':require_once'LocalSettings_help_shoopz_com.php';break;case'wiki.shoopz.net':require_once'LocalSettings_wiki_shoopz_net.php';break;default:header('HTTP/1.1 404 Not Found');echo'This wiki is not available. Check configuration.';exit(0);}

Note: To set up multiple domains that point to the same MediaWiki code, you may need to modify your web server and possibly DNS configuration.

See the documentation of your web server and or web host for information on how to do that.

If your wikis are on the same domain but different paths (e.g. yourdomain.com/wiki1, yourdomain.com/wiki2 etc), you can use something like this:

<?php// Include common settings to all wikis before this line (eg. database configuration)$callingurl=strtolower($_SERVER['REQUEST_URI']);// get the calling urlif(strpos($callingurl,'/wiki1')===0){require_once'LocalSettings_wiki1.php';}elseif(strpos($callingurl,'/wiki2')===0){require_once'LocalSettings_wiki2.php';}elseif(strpos($callingurl,'/wikiN')===0){require_once'LocalSettings_wikiN.php';}else{header('HTTP/1.1 404 Not Found');echo"This wiki (\"".htmlspecialchars($callingurl)."\") is not available. Check configuration.";exit(0);}

Note: If you use Short URL with the second case (directory based wikis), you need to check the two directories: strpos( $callingurl, 'wiki1', 0 ) || strpos( $callingurl, 'w1/', 0 ), to symlink the sources (w1 -> w), and adapt $wgScriptPath.

It may also be useful to simply redirect any unrecognized wiki URL to the "main" url, instead of "This wiki is not available. Check configuration."

Updating wikifarm from the commandline

Using EXPORT

This method requires the $_SERVER["SERVER_NAME"] to be present to run maintenance/update.php - which of course it isn't, from the commandline. This can be overcome by setting an environment variable:

SERVER_NAME=foo.subdomain.org
export SERVER_NAME
php update.php

If you were using the subdirectory method, you can use:

REQUEST_URI="/wiki1"export REQUEST_URI
php update.php

Using conf parameter

If you are using a separate LocalSettings.php file for each wiki in the family, as suggested in #Giant switch statement, then you can use the --conf parameter to tell update.php which settings file to use. For instance:

php update.php --conf ../LocalSettings_shoopz_com.php

Drupal-style sites

As above, this setup allows you to install more than one wiki using different databases on a single server, using the same source code. This setup has the advantage of being completely transparent to users and reasonably secure in terms of the images directory.

After successful installation, move LocalSettings.php into a sites directory that will be a match when the site is checked. For example, to capture http://mysite.com/mywiki, one would create the directory mysite.com.mywiki. e.g., mkdir /home/web/mediawiki/sites/mysite.com.mywiki. See the Drupal's settings.php file for more information on this.

If you intend to use media files, create an images directory in your site directory. e.g., mkdir /home/web/mediawiki/sites/mysite.com.wiki/images. Make it writable as necessary.

Modify the LocalSettings.php of each subsite to point to the right places:

First comment out the code relating to $IP, (lines 16-20 in 1.15.3) as this is set to the code directory by index.php.

Next insert the following two lines to ensure that image files are accessible, e.g.: $wgUploadDirectory = "/home/web/mediawiki/sites/wiki.mysite.com/images"; and $wgUploadPath = "/images";. These need to be put somewhere after the call to DefaultSettings.php (line 25 in 1.15.3), as the variables will otherwise be reset.

Make further modifications as required.

Prepare your Apache 2 installation. Example site: wiki.mysite.com

Create a link to the code directory, if required e.g.ln -s /home/web/mediawiki/code /home/web/wiki.mysite.com

If you are setting the sites up locally, update your hosts file with the site names.

The site should now work. In my case, I made another copy of the code from which to install and update my LocalSettings.php and databases.

Note that $_SERVER['HTTP_HOST'] in the companion Drupal code is undefined when running maintenance scripts from the command line, so this solution does not permit the use of maintenance scripts without some modification.

Modified Drupal-style method for Ubuntu

A simplified method for multiple wikis and multiple (or nested) subwikis on Ubuntu/Kubuntu that is loosely based on the above method can be found at:

Think before being creative; if you call your media-files-wiki something like "media" (e.g. media.example.com), it might collide with internal namespaces and nomenclature for embedded media files ([[media:file.ext]]).

Note: However, you should not replace the cache, mw-config(config ≤ MW 1.16.x) and images directories.

To do the same in Windows, use

mklink /D pathtolink pathtotarget

Configure

Wiki Configurations

Note: It is imperative, that you modify LocalSettings.php of your different wiki installations right from the start (even before creating the symbolic links) , or you will have /wiki/../maintenance/runJobs.php --maxjobs 1 piling up in your server's memory. Include the line below into each LocalSettings.php.

Interwiki

iw_prefix - enter the language-code of the wikis, "de" for German, "en" for English, "fr" for French and "pool" for the mediapoolwiki

iw_url - this is the place for the complete URL to the wikis, e.g. "http://de.yourwiki.org/index.php/$1" for the German wiki (don't forget the "$1" !).

Enter as many records into table Interwiki than you have different wiki (so one record for German, one for English, one for media for example).

Now you can link an article to the same in another languages. Adding [[de:Hauptseite]] on your English Main_Page will create the link "Deutsch" (under the Navigation bar) which leads to the Main_Page of the German wiki (Hauptseite). For further information visit Help:Interwiki linking

Note to page Special:Interwiki: (you will see a long table)
Add in the German wiki the prefix 'en' and the url http://en.yourwiki.org/index.php/$1 and set the checkbox 'Als lokales Wiki definiert'.
Do it in the English wiki vice versa with checkbox 'Forward'. And in both wikis enter a second prefix 'pool' and http://pool.yourwiki.org/index.php/$1 and check the checkbox 'Forward'.

Upload

Make sure that folder "images" of the pool-wiki is writable.

It is useful to change the "Upload file"-Link of the language-wikis to point to poolwiki's upload-site. Open the "LocalSettings.php" of each language-wiki and add:

Image description

This file is stored in our data-pool.
For information and description, please visit the
[[:pool:Image:{{PAGENAME}}|description there]].

(And note the ':' at the beginning of the line, which stops 'pool' from being included in the interwiki list at the left of the page.)

If you want to output the media-description, stored in the PoolWiki, too, add to the "LocalSettings.php" of the languagewikis:

$wgFetchCommonsDescriptions=true;$wgSharedUploadDBname='pool';# DB-Name of PoolWiki$wgSharedUploadDBprefix='wiki_';# Table name prefix for PoolWiki$wgRepositoryBaseUrl="http://pool.yourwiki.org/index.php/Image:";

Shared Settings

If you have multiple wikis, you'll probably want to share similar settings across them all. Here is how to do that. We recommend that you separate your Extension settings into a different file than your other settings, as detailed below. They can be all put into one large file, but it's not as flexible depending upon your specific needs.

Here is an example directory structure if you do all of the following:

Extension Settings

Create a file called ExtensionSettings.php with the following contents, and place it in a location similar to the example above.

<?php########## Extension Directory Variables######### These variables allow you to specify a single, shared directory for each grouping of extensions.## If the directory ever needs to be changed, it can be changed here rather than on every## item below. DO NOT include a trailing "/".#### Extensions from gerrit.wikimedia.org# $wgWikimediaExtensions = "/var/www/wikimediaextensions";#### Any third-party extensions# $wgOtherExtensions = "/var/www/extensions";############# Add globalized extension settings below#require_once "$wgWikimediaExtensions/ReallyCoolExtension/ReallyCoolExtension.php"; #An example Wikimedia Subversion extension entry#require_once "$wgOtherExtensions/ReallyCoolExtension/ReallyCoolExtension.php"; #An example third-party extension entry

Step 2

Edit the LocalSettings.php file of each wiki that you want to use the shared settings, and add the following.

require_once"/absolute/path/to/ExtensionSettings.php";

Step 3

Now just add all the references to your various extensions

Wiki Family Settings

These are settings that you want to apply to the entire wiki family. For example, maybe you want to be able to easily put all the wikis into read-only mode at the same time. You can also store the username/password for the database(s), if they are all the same. Additionally, you could control user permissions across your entire wiki from this one file.

Note: If you use a Images/Media commons or pool, we recommend that you do not putthese settings in the WikiFamilySettings.php file. That information only applies to every wiki in your wiki family other than your repository. We recommend putting it in a separate file.

Let's see a real example of mediawiki/LocalSettings.php. In real life we must deal with the slight differences in the names and databases of the sites we manage.

if(!defined('MEDIAWIKI')){exit;}#Protect against web entry$mysites=array(array('台掃','radioscanningtw.jidanni.org','radioscanningtw'),array('蝶園','transgender-taiwan.org','transgender'),array('ABJ','abj.jidanni.org','mwabj'));$mystrings=array($_SERVER['SCRIPT_FILENAME']);if($wgCommandLineMode){$mystrings[]=$_SERVER['PWD'];}$mystrings[]=$IP;foreach($mysitesas$site){foreach($mystringsas$string){if(strpos($string,$site[1])!==false){$wgSitename=$site[0];putenv("MW_INSTALL_PATH=/home/jidanni/".$site[1]);$wgDBname=$site[2];break2;}}}if($wgSitename=='MediaWiki'){trigger_error('Oh no, I still have not set $wgSitename. Somebody tell me. TEL +886-963-114343',E_USER_ERROR);}## For maintenance scripts, https://bugzilla.wikimedia.org/show_bug.cgi?id=19593 :if($wgServer=='http://localhost'){$wgServer=$wgInternalServer='http://'.$site[1];}$wgUsePathInfo=false;$wgScriptPath='';$wgDBserver='mysql.transgender-taiwan.org';$wgLogo="/images/$wgDBname/$wgDBname.png";switch($wgSitename){#any per-wiki customizations}

Note we still individually do database related tasks, e.g., php update.php. (The above code should detect which wiki's update.php you are referring to.) Upgrading is simple if you download from Git. (Hopefully there is no more code that assumes there is only one wiki on the disk...)

Images

Unless you do not allow uploads or allow them only for your pool wiki, you will need to create separate image directories and alias them in your vhost configuration: for i in aaa bbb ccc; do mkdir -p /home/user/images/$i; done, and in aaa.example.org's vhost: Alias /w/images /home/user/images/aaa. Same for bbb and ccc.

Adding new wikis

temporarily comment out the file_exists("../LocalSettings.php") check of config/index.php and then run it

merge the config/LocalSettings.php produced into LocalSettings.php

add some pages

Removing old wikis

To remove a wiki from a production Wiki family

remove its configuration from

web server

LocalSettings.php

DROP DATABASE

Wikimedia Method

Another option is using the method that the Wikimedia Foundation uses. The rough steps are listed below. This method isn't for the faint of heart, but it has fairly good results, as can be seen by the success the Wikimedia Foundation has had by using this :-)

Configure a template copy of MediaWiki through the online configuration wizard. Edit the Main Page if you want a default main page for every wiki you create on your farm.

After that, export your database with mysqldump, phpMyAdmin, etc. Save this on your server in the maintenance/ directory as something like template.sql.

Now, write up a few quick scripts to create a new wiki. In summary, you'll need to duplicate the database for a list of wikis (the list can be flat-file based or MySQL/SQLite based). First export the template wiki, then import the template database dump back into the database under the name of each new wiki. Use a standard suffix after the new database name (i.e. if the wiki is cat.example-farm.org, then you might choose catwiki as the database name).

Configure your DNS with a wildcard A record, and apache with a server alias (like ServerAlias *.example-farm.org) and you should be in business.

The script maintenance/update.php takes a --wiki parameter that is exported as MW_DB constant. Your LocalSettings.php file needs to set it as the correct $wgDBname. (On the command-line there is no HTTP request, and no "SERVER_NAME":

php maintenance/update.php --wiki catwiki

Your unique LocalSettings.php (which usually consists in a few lines including a CommonSettings.php not directly accessible from the server) uses the $wgDBname variable to initialise the wiki-specific settings. See Manual:$wgConf#Example for how.

You'll also need to fix the upload directories unless you want every wiki to use the same files. As said above, this is probably one of the hardest methods to do, and it requires more technical experience, but it can give really good, clean results.

Wiki Farm Extensions

There are several MediaWiki extensions that attempt to simplify hosting of several wikis by using just one code base: