Mediawiki Farm – Administer multiple wiki environments
2009/07/28 Update: I’m working on a robust version that handles the diversity of mediawiki’s databases. Therefore the script should work with newer versions of mediawiki.
2008/06/19 Update: Added entry, howto setup VirtualHosts / CNAME
2008/04/28 : version 0.4 is available.
Overview
As we all know, wiki’s are hot. And at the University we’ve got request constantly for facilitating them. BUT, there’s also a big issue and that is the fact that there isn’t any easy administration tool for installing and archiving wiki’s. So, with that in mind I started to work on a solution to administer multiple wiki’s, in this case mediawiki’s.
So, what does it need to do
Well basically, I just want to run a command line script that creates a wiki-directory linked to the source directory for easy updating and create a wiki database and user.
If this is what you want….. then read on
Server setup and software requirements
The server in question runs Linux Debian Etch. Web service is provided by Apache2, php5 and a mysql server v5 runs at localhost. The scripts I’ve created for this purpose will run on Debian, Ubuntu, Linux Mint, and lots of other Linux flavors. The script uses Debian package makepasswd. Just apt-get it and you’ll be fine. All other commands are pretty default. The mediawiki software that I’m running is version 1.12 from backports.org but it should work fine with 1.7 and I’ve tested successfully with 1.10 (Linux Mint).
If you like here is how you install mediawiki from the debian backports.org.
-
$echo deb http://www.backports.org/debian etch-backports main contrib non-free >> /etc/apt/sources.list
-
If you are using etch and you want apt to verify the downloaded backports you can import backports.org archive’s key into apt:
-
$apt-get install debian-backports-keyring
-
$apt-get update
-
And finally install mediawiki
-
apt-get -t etch-backports install mediawiki
Global architecture
When you fetch mediawiki from the repo it will be installed in /urs/share/mediawiki. This will be the “source” directory for all your wiki installations. Within the source directory there are some symbolic links to “config”, “extensions” and “images”. Hereby an overview of shared and created directories:
# Main source directory also includes, extensions, skins, languages, etc, etc.
/var/www/new_wiki -> /usr/share/mediawiki
# A separate directory for uploading files. We like to keep this separate for other wiki’s.
/var/www/new_wiki/images
NB. config is not used since we are doing a one click button install.
The script
This is a very basic bash script, easy to understand and to configure. The directory structure is as follows:
/root/mediawiki-setup/ # Base script directory
/root/mediawiki-setup/archive # Directory used when archiving a wiki. Complete wiki html directory, mysql data dump and a mysql cleanup query.
/root/mediawiki-setup/bin # Place where the script “wiki-admin” lives.
/root/mediawiki-setup/conf # Here are the default files like mediawiki database sql script, and LocalSettings.php
/root/mediawiki-setup/reports # While creating a new wiki, specific information about it will be stored in the reports directory. Per wiki it saves LocalSettings.php and the SQL create statements.
You do need to configure at least the following for the wiki-admin script:
WIKI_SOURCE=/usr/share/mediawiki # Change it if it differs from yours.
SQL_PWD=YourVeryStrongPassword # Change pwd and if you like add the server if your not on localhost.
What does it work?
Wiki-admin script wil check and create a directory at /var/www/new_wiki. Then it will create the necessary symbolic links to the source directory. Next it will create the image directory and set it up with appropriate rights. When this is done a sql script will run to create the database, db-user and rights for the db-user. Last step is setting up LocalSettings.php and copy it to the wiki directory.
For archiving just run wiki-admin archive . The script will basically backup your wiki to the archive directory (tgz) and then dump the database save it and finally drop the database and cleanup the database user and his rights.
The “WikiAdmin” account will be installed in every wiki you install. Therefore, change the WikiAdmin password. Of course you can install a test wiki, change the WikiAdmin password, drop the schema, save it in conf directory and use that for your basic wiki installation.
Here’s a code snippet, you can download it below!
-
-
# Wiki-admin: maintenance script for creating, archiving and listing mediawiki's (http://www.mediawiki.org)
-
# v 0.4, 2008-04-28 (look for latest version at http://www.jirp.nl)
-
# Copyright (c) 2008, Raymond Mul (raymond at mul.nl)
-
# Released under the MIT License (http://www.opensource.org/licenses/mit-license.php)
-
-
# Description:
-
# The latest information and a complete manual regarding this script look for it @ http://www.jirp.nl
-
-
# In short, this script let's you create multiple mediawiki's from one source directory, backup them, archive themand list them.
-
-
# This script, at the moment, has three functions:
-
# 1) create : this allows you to setup a mediawiki based on one source directory.
-
# – create directory in /var/www/;
-
# – create symbolic links to the source;
-
# – create images directory for uploading specific for that wiki;
-
# – create database, user with a strong password and grant specific rights;
-
# – create wiki tables, import sql-dump;
-
# – create LocalSettings.php and changes it so it comes wiki specific;
-
# – create reports such as database connection string, copy of sql-importand saves a copy of LocalSettings.php;
-
-
# 2) archive: at some time you may want to terminate a wiki and archive it, this option will just do that.
-
# – archive runs first the backup function to do a last minute backup;
-
# – archive cleans-up the wiki directory;
-
# – archive drops the database and the database user;
-
-
# 3) list: gives you a listing of running wiki's created with this script.
-
-
# Usage:
-
# /script/path/wiki-admin create # create wiki
-
# /script/path/wiki-admin archive # archive wiki and clean up
-
# /script/path/wiki-admin list [wiki-name|*] # list info about a wiki or without a name shows all info about all wiki's
-
-
# Requirements
-
# – makepasswd # for generating strong passwords
-
# – mysql, mysqldump # part of mysql-client package
-
# – mysql server # localhost or somewhere else you need ofcourse a mysql-server
Apache in combination with CNAMES pointing to VirtualHosts is no problem and very easy to implement.
For instance, say you have the following cnames :
wiki-1.somesite.org
wiki-2.somesite.org
- First step, create the wiki’s, just follow the script.
- Next, create the VirtualHost file in /etc/apache2/sites-available/ for wiki-1 and wiki-2 (see example below)
notice that I redirect tcp/80 directly to tcp/443. If you don’t have a certificate then remove the first VirtualHost entry and change *:443 to *:80
-
<VirtualHost *:80>
-
ServerName wiki-1.somesite.org
-
ServerAdmin admin@somesite.org
-
-
Redirect permanent / https://wiki-1.somesite.org/
-
-
</VirtualHost>
-
-
<VirtualHost *:443>
-
ServerName wiki-1.somesite.org
-
ServerAdmin admin@wiki-1.somesite.org
-
-
SSLEngine On
-
SSLCertificateFile /etc/apache2/ssl/law.pem
-
SSLCertificateChainFile /etc/apache2/ssl/sureserverEDU.pem
-
-
DocumentRoot /var/www/wiki-1
-
<Directory />
-
Options FollowSymLinks
-
AllowOverride None
-
</Directory>
-
<Directory /var/www/wiki-1/>
-
Options Indexes FollowSymLinks MultiViews
-
AllowOverride AuthConfig
-
Order allow,deny
-
allow from all
-
# This directive allows us to have apache2's default start page
-
# in /apache2-default/, but still have / go to the right place
-
# RedirectMatch ^/$ /apache2-default/
-
</Directory>
-
-
ErrorLog /var/log/apache2/wiki-1-error.log
-
-
# Possible values include: debug, info, notice, warn, error, crit,
-
# alert, emerg.
-
LogLevel warn
-
-
CustomLog /var/log/apache2/wiki-1-acces.log combined
-
ServerSignature Off
-
-
</VirtualHost>
- Enable site with: a2ensite wiki-1 && a2ensite wiki-2
- /etc/init.d/apache2 reload
- Now go to /var/www/wiki-1 and change in LocalSettings.php the following parameter:
-
original : $wgScriptPath = "/wiki-1";
-
change: $wgScriptPath = "";
This needs to be done because your VirtualHost defines your wiki location.
After download verify with: sha1sum mediawiki-setup-0.4.tgz
f2678d81aceb9d72e58d7e51c1460750376a3447 mediawiki-setup-0.4.tgz (2008/04/29)
Untar it in /root for example with: tar xvzf mediawiki-setup-0.4.tgz
If you like it, drop me a note, or if you have any questions…. drop them to.
Cheers,
Raymond.
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Hey, great write up and nice script. I have been wanting to change my setup to a MediaWiki farm for some time. I have one remaining thing to do that I can’t seem to get working properly. Basically I want to set up Apache such that each wiki can be reached directly using a specific domain name. I tried using VirtualHosts but have had no luck thus far. Suggestions?
Hi Jeremy,
Thanks for your comment! Somehow showing code in comments doesn’t work well. So I’ve created an extra entry that specifically handles the use of CNAME / VirtualHost combination.
Cheers and have fun,
Raymond
Thank you Raymond for the tutorial (and your other hint too!). I am still struggling with getting SSL working now but I think that is because all of my web traffic going through Pound the reverse-web-proxy.
Huhmmm, I took a glimpse at http://www.apsis.ch/pound/index_html. I guess you need to set up a wildcard certificate to make pound work. Security wise, I agree on not to filter with Pound but to filter with VirtualHost. Just Read That Fine Manual
Cheers,
Raymond.
Exactly what I wanted; thanks for sharing.
David
Hi, I am not able to open the zip file. I am trying to set this in my wiki farm at http://thewikiz.com
Just save it as mediawiki-setup-0.4.tgz and then run :
tar xvzf mediawiki-setup-0.4.tgz
You should be fine.
Cheers,
Raymond.
Is there a version of this for Windows? Looks impressive!
Hi Ac,
Sure you can! Have a look at http://www.cygwin.com/
Cygwin is a Linux-like environment for Windows.
Cheers,
Raymond.
On a redhat system set
MAKEPASSWD=/usr/bin/mkpasswd
and change the line (that option is a lower case L):
DB_PASSWD=`$MAKEPASSWD -l $DB_PASSWD_LENGTH`
and change the owner line to:
chown apache.apache $WIKI_DIR_IMAGES
Thanks for the script.
The script creates a new database by loading in a dump that is supplied with the script. The dump may not be from the same version of mediawiki that the user has. A more robust solution may be to create the database using the maintenance/tables.sql file that is part of the mediawiki install.
Hi, I’m interested to try your script, but the link to download it doesn’t work. Where can I download it?
Thanks
Hi Yann,
Link is fixed. Beware, executing the script will work flawlessly with mediawiki version 1.12. Currently I’m working on a more robust version that handles new mediawiki version more adequately. (as mentioned by Mark Nienberg)I will be updating the top op this article regularly.
Hi, thanks for the quick fix! I’l have a look at your script to see. Thanks for sharing!
Hi…
I already have a wikifarm running, although all of them are basically different wiki’s with some shared Settings… I figured it would be easier to use one single source code and decided to use this… But this is appearantly for people that have a server of their own… How can I use this or something similar on a Shared Hosting Plan?
I guess you need ssh access to set things up. Change some directories in the script. Find out where the database lives and make changes accordingly.
Hi Raymond!
Is there something wrong with the downloadlink?
All I see is [download#1#image] that only changes color when I mouse over it.
—Fixed—
Thanks Raymond!
And a Merry Xmas to all of you!