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.

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.