On a mobile phone? Check out aaron.pk

Aaron Parecki

creative problem solver – specializing in web development and graphic design

Multisite MediaWiki

Home > Multisite MediaWiki

A short guide to setting up MediaWiki to work on multiple websites using the same codebase.

Contents

Prerequisites

  • mod_rewrite
  • mod_env
  • Assumes you are installing multiple wikis on different domains at the root of each domain.

Apache Configuration

Set up a virtualhost block for each domain that you are hosting. All the DocumentRoots will point to the same location, the location that you extracted the MediaWiki files.

<VirtualHost *:80>
	ServerName example.com
	
	DocumentRoot /web/sites/mediawiki
	<Directory /web/sites/mediawiki>
		Options FollowSymLinks
		AllowOverride All
		allow from all

		RewriteCond %{REQUEST_FILENAME} !-f
		RewriteCond %{REQUEST_FILENAME} !-d
		RewriteRule ^(.*)$ /index.php [L,QSA]
		RewriteRule ^$ http://%{HTTP_HOST}/Main_Page [R=permanent,L]
	
		SetEnv MEDIAWIKI_PATH site1
	</Directory>

	Alias /images /web/sites/mediawiki/images/site1
</VirtualHost>

I use SetEnv to provide PHP with an environment variable accessible via $_SERVER['MEDIAWIKI_PATH'], but you could just as well use $_SERVER['SERVER_NAME'] if your files are named appropriately.

LocalSettings.php

Replace your default LocalSettings.php file with the following:

define('MW_INSTALL_PATH', dirname(__FILE__));

$wgScriptPath       = "";
$wgScriptExtension  = ".php";
$wgArticlePath = '/$1';
$wgUsePathInfo = true;

require_once('config/' . $_SERVER['MEDIAWIKI_PATH'] . '.php');

$wgUploadDirectory		= $IP . '/images/' . $_SERVER['MEDIAWIKI_PATH'];
$wgUploadPath			= $wgScriptPath . '/images';

You will then move your individual sites' LocalSettings.php files into the config/ folder and name them with the name you used for the MEDIAWIKI_PATH environment variable.

Images and Uploads

Create a subfolder in your images folder for each site. Use the identified set by MEDIAWIKI_PATH or use SERVER_NAME instead.

Installation

The only hack you'll have to do is tell config/index.php that your wiki isn't yet installed by commenting out the check for the LocalSettings.php file.

Find the call to writeSuccessMessage(); and comment out that block of code.

You should then be able to visit http://example.com/config/index.php and run through the setup process to create a new wiki. Of course you should disable access to this file as soon as you're done setting it up so it can't be abused.