User:Razool/MultipleWiki

Description: Assume that you want to provide www.username.host.domain.com for the homepage of username via just DNS A records to the same machine and without any virtualhosts on this machine.

Solution: For HTTP/1.0 requests there is no solution, but for HTTP/1.1 requests which contain a Host: HTTP header we can use the following ruleset to rewrite http://www.username.host.com/anypath internally to /home/username/anypath:

Scenario 3: Quick set-up
You want to install more than one wiki on a single server, using the same source code (i.e. single set of MediaWiki files), and using the same database?


 * 1) Install prerequisites.
 * 2) Upload MediaWiki files to web folder on the webserver.
 * 3) From browser, browse to the uploaded folder (for example, if your web server is running as   and MediaWiki files were uploaded to   folder, then the URL would be  ) which will lead to a page which gives a link to Please set up the wiki first. Click the link, fill-in the setup form, and install the first wiki (e.g., MyWiki). For details, see Manual:Config script.
 * 4) After successful installation, move LocalSettings.php into the root directory of your wiki and rename it in such a way to make it easy to track (e.g., myWikiLocalSettings.php)
 * 5) Repeat step three and four above for each wiki you wish to create, creating a new LocalSettings.php file for each wiki (e.g., anotherWikiLocalSettings.php, etc.)
 * 6) 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 $wgScriptPath in the each of the LocalSettings.php files to point to the main wiki's folder.
 * 7) Create a LocalSettings.php file for your global settings, then select one from the two possibilities below:


 * 1: If you have different domains/subdomains that link to one directory on your server, use this:
 * To link your subdomains to one directory on your server, you may have to edit the configuration file for your server (can not be done with a  file, try changing   there in Apache web server setup) or, if your site has its own IP address, modify the DNS configuration for your site.


 * OR 2: If your wikis are in different directories (e.g.,   etc) linked to the main wiki directory on your server (say  ), use this:


 * If the function strpos finds the string you search for at the beginning of $callingurl, then the function returns 0 (i.e. it found the string starting at position zero) therefore, you need to change  to.


 * If you use Short URL with the second case (directory based wikis), you need to check the two directories:, to symlink the sources , and adapt.


 * You should use "srtpos == 1" or similar instead of plain strpos to avoid redirecting to wrong wiki when the url contains the name after the beginning

You can use a different unique MySQL database for each wiki (see $wgDBname) OR you can use a different table prefix for each wiki (for Postgres, you can achieve a similar effect by using different schemas) (see $wgDBprefix).

Separate directory wikies
This works for separate directories wikies

Share resources
$wgUseSharedUploads = true;

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

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

$wgHashedSharedUploadDirectory = true;

Scenario 6: Multiple wikis through RewriteRules
This approach is based on the work of Mizanur Rahman (see Boolean Dreams Article and it has elements in common with above. Follow steps 1-5 in  to setup the individual wikis. Then modify the LocalSettings.php file for each wiki along the lines:

Wiki 1 Local Settings File:

Similarly for Wiki 2 Local Settings File:

You'll also need a master file, along the lines described in step 7 of to choose the appropriate local settings file for wiki1 or wiki2 based on a url.

Finally, in the .htaccess file you need RewriteRules to map the article urls to standard wiki urls and non-article urls to the folder containing the wiki source. Assuming the wiki source is installed in '/w/', .htaccess would be something like:

Fix for Maintenance Scripts
Maintenance scripts run directly, not via a url so the RewriteRules won't provide a suitable url for the master LocalSettings.php file to $_SERVER["SERVER_NAME"] or $_SERVER['REQUEST_URI']. To work around this, use a separate global varible to offer an alternate selection method and define the variable on the command line when calling maintenance scripts. A suitable master LocalSettings.php would be something like:

Then, when running a maintenance script, such as importImages.php from the command line:

Here the -d switch modifies the auto_prepend_file setting in php.ini to execute a file before the importImages.php script. This file sets the global variable to select the wiki:

1
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:

& in .htaccess with the wiki src in the directory /w/

Multiple Wikis, one install/config
I need to host a reasonably small number of similar wikis. I want to be able to update the source and configuration for all of them simultaneously, and have simplified maintenance. The solution I came up with is inspired by http://www.steverumberg.com/wiki/index.php?title=WikiHelp_-_Method_One and especially the reader comment about mod_rewrite. I wrote it up so I could remember, and because I thought it might be helpful. Bryan C. 68.188.91.87 05:00, 19 December 2008 (UTC)

The general idea is that we use the web server (Apache, here) to set an environment variable based on the URL. Then, in LocalSettings.php, we include a file that depends on the environment variable and contains exactly those settings needed for the selected wiki. All other settings can be shared. I have separate image directories for each wiki - I suppose this would work with a shared images directory, but I haven't tried it.

Why this is good:
 * Completely transparent to users
 * Can make a config change to all wikis at once since they all share the bulk of LocalSettings.php. For example, you can add an extension to all of them as easily as for a single wiki. You can also make settings only on some wikis, or on all but some wikis.
 * Avoids symbolic links, which will fail if the file structure of the MediaWiki install changes.
 * No need to customize maintenance scripts - just set an environment variable to choose which wiki they effect.
 * Only one directory needs to be backed up, and it's got everything.

Why you might try a different method:
 * Don't have the ability to add RewriteRules to Apache
 * Wikis will have widely differing settings/extensions.

This step-by-step shows how to set up a pair of wikis, which I'll call wiki1 and wiki2, and which are served at www.example.com/wiki1 and www.example.com/wiki2. I did this on Linux with Apache. The technique, but not the steps, should work in other settings.

Step 1: Create first wiki
In fact, I did this step a long time before moving to a multi-wiki setup. Just a normal install. If you plan to run multiple wikis under one database, you should use a different database prefix for each one.

Step 2: Add structure for separating wikis
Put a subdirectory structure on the images directory so that the images are stored in 'images/wiki1'. One way to do this is to rename images to wiki1, create a new directory images, copy wiki1 into it, then check that the permission settings are correct to allow write access by the webserver.

Split LocalSettings.php into two files, one still called "LocalSettings.php" and a second called "LocalSettings-wiki1.php". The -wiki1 file should contain only those settings which are specific to wiki1. For my setup, these were: Comments: Obviosly, you want different sitenames and possibly logos. The ScriptPath is so MediaWiki can generate pages with the correct URLs. For a single database solution, the DB variable could stay in LocalSettings.php and the site-specific file could set the prefix (mysql) or schema (postgres). The wgUpload variables set up the new images directory structure. I don't understand wgProxyKey, but I think it serves to keep a user's sessions untangled when they are logged in to multiple wikis.
 * $wgSitename = "Wiki1"
 * $wgScriptPath = "/wiki1"
 * $wgDBname
 * $wgUploadDirectory = "{$IP}/images/wiki1";
 * $wgUploadPath = "{$wgScriptPath}/images/wiki1";
 * $wgLogo
 * $wgProxyKey

Now add this to LocalSettings.php: require_once("$IP/LocalSettings-".$_SERVER["WIKI"].".php"); It includes the "LocalSettings-????.php" file depending on the state of the environment variable WIKI. I put this immediately following the require_once for DefaultSettings.

Add this line to the Apache config file: RewriteRule ^/wiki1(.*) /your/path/to/mediawiki$1 [E=WIKI:wiki1,last] The E part sets the environment variable "WIKI" to wiki1. The rest of the line is fairly standard and could be changed if needed.

At this point, you should test your single wiki and make sure everything still works, especially image upload/view.

Step 3: Add additional wiki(s)
Create the database for the new wiki and grant appropriate permissions to the DBuser, as done in a standard install (or skip this if you're using prefixes).

Create the images/wiki2 directory and set it's permissions so the webserver can write it.

Add a RewriteRule to Apache. It's the same as above, except with wiki2 in both places instead of wiki1.

Move LocalSettings.php to a different name temporarily.

Allow write permission on the config directory.

Browse to www.example.com/wiki2. It should look just like the config for a fresh install. Fill in the install form, nothing special (except the database or prefix needs to be set appropriately for wiki2).

Put back your LocalSettings.php file that you hid temporarily.

Create LocalSettings-wiki2.php. Either hand-edit a copy of LocalSettings-wiki1.php, or cut the important stuff out of the newly created config/LocalSettings.php (which is then no longer needed).

Test wiki2. Repeat step 3 to add more wikis.

Maintenance
To run a maintenance script, simply set an environment variable to pick the target wiki. For example, under Linux: WIKI=wiki1 php maintenance/checkUsernames.php

Maintenance under Windows with symlinks
How can this be done under Windwos running
 * Link Shell Extension
 * Xampp
 * Wikifarm Alt. 2

Pretty simular environment as under linux.