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.

Install mediawiki from backports.org
  1. $echo deb http://www.backports.org/debian etch-backports main contrib non-free >> /etc/apt/sources.list
  2. If you are using etch and you want apt to verify the downloaded backports you can import backports.org archive’s key into apt:
  3. $apt-get install debian-backports-keyring
  4. $apt-get update
  5. And finally install mediawiki
  6. 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!

#!/bin/bash
  1.  
  2. # Wiki-admin: maintenance script for creating, archiving and listing mediawiki's (http://www.mediawiki.org)
  3. # v 0.4, 2008-04-28 (look for latest version at http://www.jirp.nl)
  4. # Copyright (c) 2008, Raymond Mul (raymond at mul.nl)
  5. # Released under the MIT License (http://www.opensource.org/licenses/mit-license.php)
  6.  
  7. # Description:
  8. # The latest information and a complete manual regarding this script look for it @ http://www.jirp.nl
  9.  
  10. # In short, this script let's you create multiple mediawiki's from one source directory, backup them, archive themand list them.
  11.  
  12. # This script, at the moment, has three functions:
  13. # 1) create : this allows you to setup a mediawiki based on one source directory.
  14. #   – create directory in /var/www/;
  15. #   – create symbolic links to the source;
  16. #   – create images directory for uploading specific for that wiki;
  17. #   – create database, user with a strong password and grant specific rights;
  18. #   – create wiki tables, import sql-dump;
  19. #   – create LocalSettings.php and changes it so it comes wiki specific;
  20. #   – create reports such as database connection string, copy of sql-importand saves a copy of LocalSettings.php;
  21.  
  22. # 2) archive: at some time you may want to terminate a wiki and archive it, this option will just do that.
  23. #   – archive runs first the backup function to do a last minute backup;
  24. #   – archive cleans-up the wiki directory;
  25. #   – archive drops the database and the database user;
  26.  
  27. # 3) list: gives you a listing of running wiki's created with this script.
  28.  
  29. # Usage:
  30. # /script/path/wiki-admin create               # create wiki
  31. # /script/path/wiki-admin archive              # archive wiki and clean up
  32. # /script/path/wiki-admin list [wiki-name|*]              # list info about a wiki or without a name shows all info about all wiki's
  33.  
  34. # Requirements
  35. # – makepasswd                                            # for generating strong passwords
  36. # – mysql, mysqldump                                      # part of mysql-client package
  37. # – 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
  1. <VirtualHost *:80>
  2.         ServerName wiki-1.somesite.org
  3.         ServerAdmin admin@somesite.org
  4.  
  5.         Redirect permanent / https://wiki-1.somesite.org/
  6.          
  7. </VirtualHost>
  8.  
  9. <VirtualHost *:443>
  10.         ServerName wiki-1.somesite.org
  11.         ServerAdmin admin@wiki-1.somesite.org
  12.  
  13.         SSLEngine On
  14.         SSLCertificateFile /etc/apache2/ssl/law.pem
  15.         SSLCertificateChainFile /etc/apache2/ssl/sureserverEDU.pem
  16.  
  17.         DocumentRoot /var/www/wiki-1
  18.         <Directory />
  19.                 Options FollowSymLinks
  20.                 AllowOverride None
  21.         </Directory>
  22.         <Directory /var/www/wiki-1/>
  23.                 Options Indexes FollowSymLinks MultiViews
  24.                 AllowOverride AuthConfig
  25.                 Order allow,deny
  26.                 allow from all
  27.                 # This directive allows us to have apache2's default start page
  28.                 # in /apache2-default/, but still have / go to the right place
  29.                 # RedirectMatch ^/$ /apache2-default/
  30.         </Directory>
  31.  
  32.         ErrorLog /var/log/apache2/wiki-1-error.log
  33.  
  34.         # Possible values include: debug, info, notice, warn, error, crit,
  35.         # alert, emerg.
  36.         LogLevel warn
  37.  
  38.         CustomLog /var/log/apache2/wiki-1-acces.log combined
  39.         ServerSignature Off
  40.  
  41. </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:
  1. original : $wgScriptPath       = "/wiki-1";
  2. change: $wgScriptPath       = "";

This needs to be done because your VirtualHost defines your wiki location.

Download mediawiki-setup-0.4.tgz Version 0.4

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.

Post to Twitter

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.

18 Comments »

 
  • Jeremy says:

    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?

  • Raymond says:

    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

  • Jeremy says:

    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.

  • Raymond says:

    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.

  • David Davies says:

    Exactly what I wanted; thanks for sharing.

    David

  • lakshmi says:

    Hi, I am not able to open the zip file. I am trying to set this in my wiki farm at http://thewikiz.com

  • Raymond Mul says:

    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.

  • Ac says:

    Is there a version of this for Windows? Looks impressive!

  • Raymond Mul says:

    Hi Ac,

    Sure you can! Have a look at http://www.cygwin.com/
    Cygwin is a Linux-like environment for Windows.

    Cheers,
    Raymond.

  • Mark Nienberg says:

    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.

  • Mark Nienberg says:

    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.

  • Yann says:

    Hi, I’m interested to try your script, but the link to download it doesn’t work. Where can I download it?

    Thanks

  • Raymond Mul says:

    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.

  • Yann says:

    Hi, thanks for the quick fix! I’l have a look at your script to see. Thanks for sharing!

  • Ted says:

    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?

  • Raymond Mul says:

    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.

  • Dixon says:

    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—

  • Dixon says:

    Thanks Raymond!

    And a Merry Xmas to all of you!

 

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

 

Twitter links powered by Tweet This v1.6.1, a WordPress plugin for Twitter.