2015-07-23

old version of Wiki family, before it got disrupted

New page

This page should lead you through the installation and configuration of a small '''wiki-family'''.

==Scenario 1: Using Virtual Directories with shared-hosting provider to Display Multiple Wikis==

This approach takes advantage of [[w:Symbolic_link|symlinks]] on a Unix-based system. This technique can also be used on Windows systems, by installing a program ([http://technet.microsoft.com/en-us/sysinternals/bb896768 Junction], [http://schinagl.priv.at/nt/hardlinkshellext/hardlinkshellext.html Link Shell Extension]) providing symbolic links or using the integrated "''mklink''" command in newer versions of Windows.

How to use "virtual directories" to operate '''more than one wiki on a single server''', using the '''same source code''' (i.e. single set of MediaWiki files), using the '''same database''', on a Unix-based system on a shared host:

See [http://www.steverumberg.com/wiki/WikiHelp_-_Method_One Steve Rumberg's "Method 1"], including step-by-step, detailed instructions

Note that using a language subdomain similar to Wikipedia (en.example.com, fr.example.com and so on) will allow you to produce the capabilities of Steve Rumberg's "[http://www.steverumberg.com/wiki/index.php?title=WikiHelp_-_Method_Two Method 2]" while providing a simple differentiation of the two wikis through the use of a web server's virtual host capability.

==Scenario 2: 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'''?

# Install prerequisites.

#Upload MediaWiki files to web folder on the webserver.

# From browser, browse to the uploaded folder (for example, if your web server is running as <code>http://localhost</code> and MediaWiki files were uploaded to <code>/testwiki/</code> folder, then the URL would be <code>http://localhost/testwiki</code>) 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]].

# After successful installation, '''move''' [[Manual:LocalSettings.php|LocalSettings.php]] into the root directory of your wiki and '''rename it''' in such a way to make it easy to track (e.g., ''LocalSettings_myFirstWiki.php'')

# Repeat step ''three'' and ''four'' 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 '''[[Manual:$wgScriptPath|$wgScriptPath]]''' in the 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 domains/subdomains that link to one directory on your server, use this:

<source lang="php">

<?php

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:

echo "This wiki is not available. Check configuration.";

exit( 0 );

}

</source>

::{{TNT|Note}}To link your subdomains to one directory on your server, you may have to edit the configuration file for your server (cannot be done with a <code>.htaccess</code> file, try changing <code>httpd-vhosts.txt</code> there in Apache web server setup) or, if your site has its own IP address, modify the DNS configuration for your site.

::* If your wikis are in different directories (e.g. <code>yourdomain.com/wiki1</code>, <code>yourdomain.com/wiki2</code> etc) linked to the main wiki directory on your server (say <code>yourdomain.com/w</code>), use this:

<source lang="php">

<?php

$callingurl = strtolower( $_SERVER['REQUEST_URI'] ); // get the calling url

if ( 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 {

echo "This wiki (\"" . $callingurl . \"") is not available. Check configuration.";

exit(0);

}

</source>

::{{TNT|Note}} 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 <code>if ( strpos( $callingurl,'wikiN' ) )</code> to <code>if ( strpos( $callingurl,'wikiN' ) !== false )</code>.

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

::{{TNT|Note}} You should use "strpos() == 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 [[Manual:$wgDBname|$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 [[Manual:$wgDBprefix|$wgDBprefix]]).

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

===Updating wikifarm from the commandline===

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 creating a simple php script, "update_subdomain.php" (all of this is done in the mediawiki base install directory):

<source lang="php">

<?php

$sub = $argv[1]; //$argv gets commandline arguments

// set domain name

$_SERVER['SERVER_NAME'] = $sub . '.domain.org';

echo '--------------------------------------

Running update.php for ' . $sub . '.domain.org

--------------------------------------

';

include("maintenance/update.php");

</source>

You can now run the code with:

<source lang="bash">

php update_subdomain.php subdomain_prefix

</source>

{{TNT|Note}} It seems to not be possible to run the update script multiple times from the same php script (ie. in a loop), as the runs after the first don't recognise the changed $_SERVER['SERVER_NAME']. (Perhaps try setting the dependent variables directly, as in [[#Ultimate minimalist solution]]?) This can be overcome by creating a bash script to run the php script multiple times (called "update_wikifarm.sh"):

<source lang="bash">

#!/bin/bash

subdomains=( meta en fr de es pl pt ja nl it sv ru zh )

for sub in ${subdomains[@]}

do

php update_subdomain.php $sub

done

</source>

Change the subdomain prefixes to suit your wikifarm, then Make the script executable, and run it:

<source lang="bash">

chmod ug+x update_wikifarm.sh ./update_wikifarm.sh

</source>

==Scenario 3: 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.

* Create a base directory to contain all your MediaWiki files ''e.g.'', <code>mkdir /home/web/mediawiki</code>.

* Install MediaWiki and additional tools as usual to a version-declaring subdirectory(''e.g.'', <code>/home/web/mediawiki/mediawiki-1.10.0</code>).

* Link the version-declaring directory to a code directory. ''e.g.'', <code>ln -s /home/web/mediawiki/mediawiki-1.10.0 /home/web/mediawiki/code</code>

* Create a ''sites'' directory to contain our images and settings: <code>mkdir /home/web/mediawiki/sites</code>

* Setup the wiki as normal from the ''/code'' 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 <nowiki>http://mysite.com/mywiki</nowiki>, one would create the directory '''mysite.com.mywiki'''. ''e.g.'', <code>mkdir /home/web/mediawiki/sites/mysite.com.mywiki</code>. 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.'', <code>mkdir /home/web/mediawiki/sites/mysite.com.wiki/images</code>. Make it writable as necessary.

* Place the [[Manual:Wiki family/Drupal-style LocalSettings.php|Drupal-style LocalSettings.php]] file in your main directory: <code>cp DrupalLocalSettings.php /home/web/mediawiki/code/LocalSettings.php</code>

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

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

**Next insert the following two lines to ensure that image files are accessible, ''e.g.'': <code>$wgUploadDirectory = "/home/web/mediawiki/sites/wiki.mysite.com/images";</code> and <code>$wgUploadPath = "/images";</code>. These need to be put somewhere after the call to <code>DefaultSettings.php</code> (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.'' <code>ln -s /home/web/mediawiki/code /home/web/wiki.mysite.com</code>

** Create an appropriate VHost configuration:

<pre>

<VirtualHost *:80>

ServerAdmin me@myserver.com

DocumentRoot /home/web/wiki.mysite.com

ServerName wiki.mysite.com

CustomLog /var/log/apache2/wiki.mysite.log common

# Alias for the site to be accessible

Alias /mediawiki/code /home/web/mediawiki/code

# Alias for Wiki so images work

Alias /images /home/web/mediawiki/sites/wiki.mysite.com/images

# If you want to password protect your site

# <Directory /home/web/wiki.mysite.com>

# AuthType Basic

# AuthName "My protected Wiki"

# AuthUserFile /etc/apache2/htpasswd/users-mywiki

# require valid-user

# </Directory>

</VirtualHost>

</pre>

* If you are setting the sites up locally, update your <code>hosts</code> 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 <code>$_SERVER['HTTP_HOST']</code> 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 (K)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:

*[http://ubuntuguide.org/wiki/MediaWiki_tips Ubuntuguide.org MediaWiki tips]

==Scenario 4: Multiple wikis sharing common resources==

You want to have some wikis in different languages, sharing the same media-files in another, single wiki.

For example:

*en.yourwiki.org - English language

*fr.yourwiki.org - French language

*de.yourwiki.org - German language

*pool.yourwiki.org - media-files for all of these wikis (like Commons).

** ''As there is already an [[Help:Interwiki linking|Interwikilink]] named <tt>commons</tt> for [[commons:Main Page|Wikimedia Commons]], we name our media-files-wiki "'''pool'''".''

** ''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 (<nowiki>[[media:file.ext]]</nowiki>)''.

===[[Installation|Install]]===

On your file system, create a folder for each wiki. Run the install script for each wiki.

This solution duplicates source code. To reduce this duplication and improve cache performance, you may wish to replace the <code>bin</code> (≤ MW 1.20.x), <code>docs</code>, <code>extensions</code>, <code>includes</code>, <code>languages</code>, <code>maintenance</code>, <code>math</code> (≤ MW 1.17.x), <code>resources</code>, <code>serialized</code><ref>[[Thread:Project:Support desk/About symlinking the "serialised" directory|See this thread concerning the "serialised" folder]]</ref>, <code>skins</code>, <code>tests</code> and <code>vendor</code> (≥ MW 1.22.x<ref>In case you are using [[Composer]] to install some or all extensions, if supported</ref>) directories for non-pool installations with symbolic links to the pool's directories:

For example, enter'' <syntaxhighlight lang="bash">rm -R extensions/</syntaxhighlight> ''and then enter'' <syntaxhighlight lang="bash">ln -s pathtopool/extensions/ extensions</syntaxhighlight>

{{Note| Don't forget to allow your Apache to '''''Follow Symbolic Link''''' editing your <code>httpd.conf</code> adding <code>FollowSymLinks</code> options}}

{{Note|However, you '''''should not''''' replace the <code>cache</code>, <code>mw-config</code>(<code>config</code> ≤ MW 1.16.x) and <code>images</code> directories.|gotcha}}

To do the same in Windows, use <syntaxhighlight lang="bash">mklink /D pathtolink pathtotarget</syntaxhighlight>

===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 <code>/wiki/../maintenance/runJobs.php --maxjobs 1</code> piling up in your server's memory. Include the line below into each LocalSettings.php.

$wgJobRunRate = 0;

====[[Help:Interwiki linking|Interwiki]]====

Now you have to set [[Help:Interwiki linking|Interwikilinks]] between all wikis, by editing their MySQL-Databases (if you prefer, install and use [[Extension:Interwiki]])

*Table '''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. "<nowiki>http://de.yourwiki.org/index.php/$1</nowiki>" for the German wiki (don't forget the "$1" !).

Now you can link an article to the same in another languages. Adding <nowiki>[[de:Hauptseite]]</nowiki> on your English Main_Page will create a 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)<br/>

Add in the german wiki the prefix 'en' and the url <nowiki>http://en.yourwiki.org/index.php/$1</nowiki> and set the checkbox 'Als lokales Wiki definiert'.<br/> Do it in the english wiki vice versa with checkbox 'Forward'. And in both wikis enter a second prefix 'pool' and <nowiki>http://pool.yourwiki.org/index.php/$1</nowiki> 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:

<source lang="php">$wgUploadNavigationUrl = "http://pool.yourwiki.org/index.php/Special:Upload";</source>

In 1.17, you'll also have to set $wgUploadMissingFileUrl to be redirected to the pool-wiki on red links.

<source lang="php">$wgUploadMissingFileUrl= "http://pool.yourwiki.org/index.php/Special:Upload";</source>

====Use shared files====

To use poolwiki's files in the languagewikis, open "LocalSettings.php" for each languagewiki and add:

<source lang="php">

$wgUseSharedUploads = true;

$wgSharedUploadPath = 'http://pool.yourwiki.org/images';

$wgSharedUploadDirectory = '/(LOCALPATH)/POOL-FOLDER/images/';

$wgHashedSharedUploadDirectory = true;

</source>

Now you can integrate pool's files with (e.g.) <nowiki>[[Image:MyLogo.png]]</nowiki> in the languagewikis.

====Image description====

In each languagewiki, open (as an admin) the message [[MediaWiki:Sharedupload-desc-here]].

Change the text to something like:<!-- ( old line ) [[pool:Image:{{PAGENAME}}|description there]]. -->

<pre>

This file is stored in our data-pool. For information and description, please visit the

[[:pool:Image:{{PAGENAME}}|description there]].

</pre>(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:

<source lang="php">

$wgFetchCommonsDescriptions = true;

$wgSharedUploadDBname = 'pool'; # DB-Name of PoolWiki

$wgSharedUploadDBprefix = 'wiki_'; # Table name prefix for PoolWiki

$wgRepositoryBaseUrl = "http://pool.yourwiki.org/index.php/Image:";

</source>

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

<pre>

en/

es/

pl/

ja/

pool/

ExtensionSettings.php

WikiFamilySettings.php

SharedMediaSettings.php

</pre>

=====Extension Settings=====

*'''Step 1'''

*:'''Create''' a file called '''ExtensionSettings.php''' with the following contents, and place it in a location similar to the [[#Shared Settings|example above]].

<source lang="php">

<?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 svn.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

</source>

*'''Step 2'''

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

<source lang="php">

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

</source>

*'''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 put''' [[#Use shared files|these 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 [[#Media Settings|separate file]].

====Shared database tables====

See [[Manual:Shared database]] for instructions on setting up shared database tables.

==Scenario 5: Multiple wikis through RewriteRules with parent wiki==

This approach has elements in common with [[#Scenario_2:_Quick_set-up|Scenario 2]] above. '''Be advised that the folks at mediawiki do not recommend using a parent wiki with wikis inside it,''' the use of a parent wiki is not required.

In this scenario, wikis are being deployed for a variety of teams and a url hierarchy was desired to make it obvious where the main/home wiki was located. As such the team wiki urls would need to be one level up from the home wiki.

To make this manageable you would need use the same wiki source code and preferably use one database. The approach below has been updated and was tested on Ubuntu 10.04 with 1.18 (This process should work with 1.16+)

=== Install ===

Follow steps 1-7 in [[#Scenario_2:_Quick_set-up|Scenario 2]] to setup the individual wikis, some steps will be explained again for clarity.

==== Parent Wiki ====

Unlike the other wikis, the parent wikis LocalSettings.php will for the most part remain untouched as all variables will default to the correct locations and the url for it will be http://domain.com/wiki. Once it has been created rename it to LocalSettings_def.php

=== Configure ===

Assuming you are setting up the wikis to use sub-directories (/wiki/wiki1, /wiki/wiki2), define the master LocalSettings.php file in this manner:

<source lang="php">

$callingURL = strtolower( $_SERVER['REQUEST_URI'] ); // the requesting url

if ( strpos( $callingURL, 'wiki1' ) ) {

require_once 'LocalSettings_wiki1.php';

} elseif ( strpos( $callingURL, 'wiki2' ) ) {

require_once 'LocalSettings_wiki2.php';

} else {

require_once 'LocalSettings_def.php';

}

</source>

Note that in this example if the url designates a non-existant wiki or isn't pointing to one (e.g http://mysite.com/wiki/nowiki or http://mysite.com/wiki/) it will default to LocalSettings_def.php which is the master wiki located at /wiki.

Modify the LocalSettings_wiki#.php file for each wiki to give each an unique url:

* '''Wiki 1 Local Settings File:'''

<source lang="php">

$wgScriptPath = "/wiki/wiki1"; // Virtual path to the files

$wgArticlePath = "/wiki/wiki1/$1"; // Gives us Wikipedia style urls for articles. The $1 is also needed for the Master LocalSettings.php

$wgUsePathInfo = true; #Pretty URL

</source>

* '''Wiki 2 Local Settings File:'''

<source lang="php">

$wgScriptPath = "/wiki/wiki2"; // Virtual path to the files

$wgArticlePath = "/wiki/wiki2/$1"; // Gives us Wikipedia style urls for articles. The $1 is also needed for the Master LocalSettings.php

$wgUsePathInfo = true; #Pretty URL

</source>

Due to how RewriteRules behave, it's best to point to the parent wiki skins directory:

<source lang="php">

$wgStylePath = "/wiki/skins";

$wgStyleDirectory = "/var/www/wiki/skins";

</source>

And then to avoid problems with the cache (pages being served up from another wiki with the same title such as Main_Page) you should modify [[Manual:$wgCacheDirectory|$wgCacheDirectory]] to point each to a unique directory. When you create the directory verify that the permissions are set to 755 and that the user apache runs under owns it.

<source lang="php">

$wgCacheDirectory = "$IP/cache/wiki1"; #Declare where cache files are stored

$wgFileCacheDirectory = "$wgCacheDirectory/html"; #OPTIONAL

</source>

It's highly recommended that you created a GlobalSettings.php file to store settings shared across wikis to simplify setup. Primary reason for doing so is if certain variables are not declared the defaults will use [[Manual:$wgScriptPath|$wgScriptPath]] as the base which can cause problems. Here is an example:

* GlobalSettings.php

<source lang="php">

#Make sure each wiki uses a valid path

$IP = "/var/www/wiki";

#mod_rewrite causes problems with styling, so lets use the real load.php

$wgLoadScript = "/wiki/load$wgScriptExtension";

</source>

Then simply add this file as an include in each wikis LocalSettings.php file.

=== Setup Rewrites ===

In the httpd file you need RewriteRules to map the wikis properly. If you do not have root access to the web server, you can also put this in .htaccess excluding the Directory tags. Assuming the wiki source is installed in /var/www/wiki/, you will want something similar to this:

<source lang="dos">

<Directory /var/www>

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^wiki/(.+)$ wiki/index.php/title=$1 [PT,L,QSA]

</Directory>

</source>

Take a look at [[Manual:Short_URL/Apache_Rewrite_rules|Apache_Rewrite_rules]] if the above does not work for you.

=== Shared Users and permissions ===

Since this use case is for an internal group, sharing users and groups across the wikis is desired to simplify management. To do so we'll use a [[Manual:Shared_database|Shared Database]] to pull this off. Add the following to GlobalSettings.php:

<source lang="php">

#Shares Users and Groups across wikis

$wgSharedDB = 'my_wiki';

$wgSharedPrefix = ''; // Must be specified as it will default to the current wikis prefix

$wgCookieDomain = '.domain.com';

array_push($wgSharedTables, "user", "user_groups");

</source>

If you intend to let each team manage access of their wiki, you will need to reset permissions for the roles on other wikis as since the roles are shared across the wiki family a user from wiki1 with role wiki1_sysop that has sysop permissions will retain those permissions in wiki2. Take a look [[Manual:Shared_database#Caveats_2|here]] for a workaround. Once you have done so, you should also read up on [[Manual:Preventing access|Preventing access]]

===== Notes =====

* This approach is based on the work of Mizanur Rahman (see [http://booleandreams.wordpress.com/2007/06/12/running-multiple-instance-of-mediawiki-on-the-same-server-using-the-same-source-code/ Boolean Dreams Article])

== Ultimate minimalist solution==

The "ultimate minimalist solution" consists of [[w:Symbolic_links|symlinks]],

$ ls -og

lrwxrwxrwx 1 16 2008-11-03 06:29 aaa.example.org -> mediawiki

lrwxrwxrwx 1 16 2008-11-03 06:29 bbb.example.org -> mediawiki

lrwxrwxrwx 1 16 2008-11-03 06:29 ccc.example.org -> mediawiki

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

<source lang="php">

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 ( $mysites as $site ) {

foreach ( $mystrings as $string ) {

if ( strpos( $string, $site[1] ) !== false ) {

$wgSitename = $site[0];

putenv( "MW_INSTALL_PATH=/home/jidanni/" . $site[1] );

$wgDBname = $site[2];

break 2;

}

}

}

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

}

</source>

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 SVN]].

(Hopefully there is no more [[Bugzilla:11654|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: <code>

for i in aaa bbb ccc; do mkdir -p /home/user/images/$i; done</code>, and in aaa.example.org's vhost:

<code>Alias /w/images /home/user/images/aaa</code>. Same for bbb and ccc.

However you may instead just prefer

[[Manual:Image Administration#Alternative simple setup]],

where *.example.org/images/ just point to the same single directory.

Or one could use e.g., *.example.org/$wgDBname/images/.

===Adding new wikis===

To add a wiki to a production {{PAGENAME}}

#add its configuration to your web server

#temporarily comment out the <code>file_exists("../LocalSettings.php")</code> 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 {{PAGENAME}}

#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 :-)

<ol>

<li>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.</li>

<li>After that, export your database with [http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html mysqldump], phpMyAdmin, etc. Save this on your server in the maintenance/ directory as something like <code>template.sql</code>.</li>

<li>Now, write up a few quick scripts to create a new wiki. In a gist, you'll need to add it to a list of wikis, which can be flat-file based or MySQL/SQLite based, and then import the template database dump back into the database under the name of a new wiki. Use a standard suffix after the new database name (i.e. if the wiki is '''meta.yourdomain.net''', then you might choose '''metawiki''' as the database name).</li>

<li>In your configuration file, add something like this, fixing the database prefix and your domain as necessary:

<source lang="php">

if ( preg_match( '/^(.*)\.yourdomain.net$/', $server, $matches ) ) {

$wikiname = $matches[1];

} else {

die( "Invalid host name, can't determine wiki name" );

// You could also redirect to a nicer "No such wiki" page.

}

if( $wikiname == "www" ) {

// Change this to your "main" wiki.

$wikiname = "meta";

}

$wgDBname = $wikiname . "wiki";

</source></li>

<li>Configure your DNS with a wildcard A record, and apache with a server alias (like <code>ServerAlias *.yourdomain.net</code>) and you should be in business.</li>

</ol>

The script maintenance/update.php can be included from a another php script, ''update_farm.php'' for example, and this outer script will set the various SERVER values that are needed by your LocalSettings.php to set the correct $wgDBname:

<source lang="php">

<?php

# update_farm.php script

$_SERVER['SERVER_NAME'] = $argv[1];

$_SERVER['DOCUMENT_ROOT']= $argv[2]; #optional

include("maintenance/update.php")

</source>

and the command line for updating '''meta.yourdomain.net''' is, from your unique mediawiki directory:

php update_farm.php meta.yourdomain.net

Your unique LocalSettings.php (which usually consists in a few lines including a CommonSettings.php not directly accessible from the server) decodes the variable '''meta''' and will set the $wgDBname accordingly.

The DOCUMENT ROOT directory (similar to the value set in your httpd.conf) can also be used in your CommonSettings.php in order to have more flexibility, like using a test server.

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:

* [[Extension:Farmer]]

* [[Extension:WikiFarm]]

* [[Extension:Simple Farm]]

== See also ==

* [[Requests for comment/Configuration database|Configuration database]]

* [[Extension:CentralAuth]]

* [[Manual:InitialiseSettings.php]] & [[Manual:CommonSettings.php]]

* [[Project:MediaWiki Farmers user group|MediaWiki Farmers user group]] and [[mail:Wikifarm]]

== References ==

<references/>

<!--[[Category:MediaWiki configuration{{translation}}|Wiki family]]

[[Category:Installation{{translation}}|W]]

[[Category:Wiki farm{{translation}}| ]]-->

Show more