Mediawiki farm setup

From Smith family

Jump to: navigation, search
Server setup
← Previous Next →
Web server Webmail

Many of the virtual web hosts on the server will run Mediawiki instances, with a separate Mediawiki for each virtual host. Setting them up isn't really any more complicated than setting up a single Mediawiki instance, but a little care is needed.

Contents

Install the packages

root@server:~# apt-get install mediawiki mediawiki-extensions mediawiki-math

Creating the farm

The basic idea is that each Mediawiki has a its own database and its own copy of all the Mediawiki configuration and files. We can cheat slightly by having each Mediawiki instance contain a link to a single set of program files, but all the configuration files are unique to each Mediawiki instance.

  • For each wiki, create a directory where the wiki's files will sit:
root@server:~# mkdir -p /var/www/site.domain.tld/mediawiki
root@server:~# cd /var/www/site.domain.tld/mediawiki
Note that the mediawiki's pages will have the mediawiki in their path, but we'll get rid of that in a moment. Don't be tempted to install Mediawiki in the document root.
  • Create the symlinks for all the shared parts of Mediawiki:
root@server:/var/www/site.domain.tld/mediawiki# ln -s /usr/share/mediawiki/api.php
root@server:/var/www/site.domain.tld/mediawiki# ln -s /var/lib/mediawiki/extensions/ 
root@server:/var/www/site.domain.tld/mediawiki# ln -s /usr/share/mediawiki/img_auth.php
root@server:/var/www/site.domain.tld/mediawiki# ln -s /usr/share/mediawiki/includes/ 
root@server:/var/www/site.domain.tld/mediawiki# ln -s /usr/share/mediawiki/index.php 
root@server:/var/www/site.domain.tld/mediawiki# ln -s /usr/share/mediawiki/install-utils.inc
root@server:/var/www/site.domain.tld/mediawiki# ln -s /usr/share/mediawiki/languages/
root@server:/var/www/site.domain.tld/mediawiki# ln -s /usr/share/mediawiki/maintenance/
root@server:/var/www/site.domain.tld/mediawiki# ln -s /usr/share/mediawiki/opensearch_desc.php
root@server:/var/www/site.domain.tld/mediawiki# ln -s /usr/share/mediawiki/profileinfo.php 
root@server:/var/www/site.domain.tld/mediawiki# ln -s /usr/share/mediawiki/redirect.php
root@server:/var/www/site.domain.tld/mediawiki# ln -s /usr/share/mediawiki/redirect.phtml
root@server:/var/www/site.domain.tld/mediawiki# ln -s /usr/share/mediawiki/skins/
root@server:/var/www/site.domain.tld/mediawiki# ln -s /usr/share/mediawiki/StartProfiler.php
root@server:/var/www/site.domain.tld/mediawiki# ln -s /usr/share/mediawiki/Test.php
root@server:/var/www/site.domain.tld/mediawiki# ln -s /usr/share/mediawiki/thumb.php
root@server:/var/www/site.domain.tld/mediawiki# ln -s /usr/share/mediawiki/trackback.php
root@server:/var/www/site.domain.tld/mediawiki# ln -s /usr/share/mediawiki/wiki.phtml
  • Create copies of the files that need to be unique to this wiki
root@server:/var/www/site.domain.tld/mediawiki# cp -r /usr/share/mediawiki/upload .
root@server:/var/www/site.domain.tld/mediawiki# cp -r /var/lib/mediawiki/config .
root@server:/var/www/site.domain.tld/mediawiki# chown -R www-data:www-data upload
root@server:/var/www/site.domain.tld/mediawiki# chown -R www-data:www-data config
  • Now modify the Apache configuration file for this site, /etc/apache2/sites-available/site.domain.tld:
<VirtualHost *:80>
       ServerAdmin webmaster@localhost

       DocumentRoot /var/www/site.domain.tld
       ServerName site.domain.tld
       ServerAlias domain.tld

       Alias /mediawiki /var/www/site.domain.tld/mediawiki

       <Directory /var/www/site.domain.tld/mediawiki/>
               Options +FollowSymLinks
               AllowOverride All
               order allow,deny
               allow from all
       </Directory>

       # some directories must be protected
       <Directory /var/www/site.domain.tld/mediawiki/config>
               Options -FollowSymLinks
               AllowOverride None
       </Directory>
       
       <Directory /var/www/site.domain.tld/mediawiki/upload>
               Options -FollowSymLinks
               AllowOverride None
       </Directory>

       # Rewrite rule will go here: see below 

       ErrorLog /var/log/apache2/error.log

       # Possible values include: debug, info, notice, warn, error, crit,
       # alert, emerg.
       LogLevel warn

       CustomLog /var/log/apache2/access.log combined
       ServerSignature On
</VirtualHost>
  • Restart Apache
root@server:~# /etc/init.d/apache2 reload
  • Now got to http://site.domain.tld/mediawiki/ and follow the instructions to set up the wiki. Make sure that you give each wiki a distinct database name.
  • Copy the config/LocalSettings.php file into the mediawiki root
  • Ensure that the wiki program knows where the files are: modify /var/www/site.domain.tld/mediawiki/LocalSettings.php to include the line
$IP = "/var/www/site.domain.tld/mediawiki";
just after the default definition of $IP at the top of the file.
  • With the wiki set up, remove the config directory
root@server:/var/www/site.domain.tld/mediawiki# rm -r /var/lib/mediawiki1.7/config 

That should be everything needed to get the wiki working.

  • Modify the LocalSettings.php file. The changes are marked below with ###
# $IP = "/var/lib/mediawiki1.7";
$IP = "/var/www/site.domain.tld/mediawiki";			###

$wgScriptPath       = "/mediawiki";				###
$wgScript           = "$wgScriptPath/index.php";
$wgRedirectScript   = "$wgScriptPath/redirect.php"; 

## If using PHP as a CGI module, the ?title= style usually must be used.
# $wgArticlePath      = "$wgScript/$1";
# Use this for the re-written, pretty URIs
$wgArticlePath      = "/$1";					###
# $wgArticlePath      = "$wgScript?title=$1";

$wgStylePath        = "$wgScriptPath/skins";
$wgStyleDirectory   = "$IP/skins";
$wgLogo             = "$wgStylePath/common/images/wiki.png";

$wgUploadPath       = "$wgScriptPath/upload";			###
$wgUploadDirectory  = "$IP/upload";				###

Rewriting paths

Now to get rid of the /mediawiki/ portion of page names in the Mediawiki. We'll do that with Apache's path rewriting engine.

  • Enable the rewriting module
 root@server:~# a2enmod rewrite
  • Modify the /etc/apache2/sites-available/site.domain.tld file, in the place specified above.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(stylesheets|images|skins)/
RewriteCond %{REQUEST_URI} !^/(redirect|texvc|index).php
RewriteCond %{REQUEST_URI} !^/error/(40(1|3|4)|500).html
RewriteCond %{REQUEST_URI} !^/favicon.ico
RewriteCond %{REQUEST_URI} !^/robots.txt

# Rewrite http://wiki.domain.tld/article properly, this is the main rule
RewriteRule ^/(.*)$ /index.php/?title=$1 [L,QSA]
  • Reload Apache's confiuration
root@server:~# /etc/init.d/apache2 reload
  • Modify LocalSettings.php by adding the $wgArticlePath and $wgUsePathInfo settings below:
$wgScriptPath       = "/mediawiki";
$wgScriptExtension  = ".php";

# Site-specific settings
$wgArticlePath      = "/$1";
$wgUsePathInfo      = false;

(apparently, this is because of a bug in Mediawiki 1.11)

You should now be able to go to http://site.domain.tld/Main_Page and see the main page of the wiki.

Tweaking Mediawiki

There are still a few things that need doing in Mediawiki to smooth off some rough edges.

Restricting editing

To prevent vandalism of the wiki, we want to restrict account creation to sysops, and prevent any anonymous editing of the wiki. Add these lines to the end of the LocalSettings.php file:

# Prevent vandalism of the wiki

# Prevent new user registrations except by sysops
$wgGroupPermissions['*']['createaccount'] = false; 

# Disable anonymous editing
$wgGroupPermissions['*']['edit'] = false;

Restricting viewing

If you want to restrict access to the wiki, add the following to LocalSettings.php to ensure that people can only access the wiki's main page.

# Disable anonymous browsing
$wgWhitelistRead = array( "Main Page", "Special:Userlogin", "-", 
    "MediaWiki:Monobook.css", "MyWiki:Privacy policy", 
    "MyWiki:About", "MyWiki:General disclaimer");
$wgGroupPermissions['*']['read'] = false;

Robots file and favicon

Simply put these files in the document root, /var/www/site.domain.tld.

Enabling uploads

In LocalSettings.php, modify the $wgEnableUploads setting:

$wgEnableUploads = true;

Extending uploadable files

Out of the box, Mediawiki only allows the uploads of image files. It allow more file types to be uploaded, include this line in LocalSettings.php

## Allow more file types to be uploaded
$wgFileExtensions = array_merge( $wgFileExtensions, array( 'pdf', 'doc', 'xls', 'ppt', 'odt', 'odc', 'odp', 'odg', 'odi', 'gz', 'zip' ) );

You'll need to do this for each Mediawiki instance. There are also some MIME types that Mediawiki doesn't know about. Edit these lines in /usr/share/mediawiki/includes/mime.types:

application/msword doc xls ppt # Added xls, ppt
application/x-gzip gz tgz # Added tgz
application/zip zip jar xpi  sxc stc  sxd std   sxi sti   sxm stm   sxw stw  odt ott oth odm odg otg odp otp ods ots odc odf odb odi oxt # Added od* and ot*

(Following the instructions at MediaWiki.org on $wgFileExtensions and MIME type validation.)

Adding a logo

  • Create your logo as a 135x135 px PNG file.
  • Upload it to the wiki.
  • Open the file in Mediawiki to find the path where Mediawiki has stored it: it will be something like http://site.domain.tld/mediawiki/upload/7/77/Logo.png : note the path name.
  • Modify the LocalSettings.php file as shown. Add the lines just below the $wgEnableUploads assignment. Note that the definition of the logo file is moved to after the definition of the upload directory pathname.
$wgUploadPath       = "$wgScriptPath/upload";
$wgUploadDirectory  = "$IP/upload"; 

$wgLogo             = "$wgUploadPath/7/77/Logo.png";

Enabling equation display

Given the mediawiki-math pagkage is installed, it can be enabled with a simple edit of LocalSettings.php:

$wgUseTeX           = true;

Installing 'Help' pages

Basic Mediawiki installations don't come with any help pages. To copy the help pages from an existing wiki, go to the 'Special Pages':'Export' page on the existing wiki, and export the following set of pages:

  • Help:Contents
  • Help:Navigation
  • Help:Searching
  • Help:Tracking_changes
  • Help:Editing_pages
  • Help:Starting_a_new_page
  • Help:Formatting
  • Help:Links
  • Help:Categories
  • Help:Images
  • Help:Templates
  • Help:Tables
  • Help:Variables
  • Help:Managing_files
  • Help:Preferences
  • Help:Skins
  • Help:Namespaces
  • Help:Interwiki_linking (don't include)
  • Help:Special pages
  • Template:PD_Help_Page
  • Template:Admin_tip
  • Template:Prettytable
  • Template:Hl2
  • Template:Hl3
  • Template:Thankyou
  • Image:Example.jpg
  • Image:Geographylogo.png
  • Image:Tools.png
  • Image:M-en-sidebar.png
  • Image:M-en-pagetabs.png
  • Image:M-en-userlinks.png
  • Image:M-en-recentchanges.png
  • Template:Click
  • Template:Languages
  • Help:Range_blocks
  • Help:Managing_user_rights
  • Help:Copying
  • Category:Help
  • Category:Category

You'll also need to download the images themselves. Then, import the pages into the new Mediawiki and upload the pages. You'll probably want to modify the PD_Help_Page template.

Upgrading from previous versions

The default way to do this is to run the update.php script. Trouble is, that doesn't work because Ubuntu seem to have misplaced the AdminSettings.php file. Also, with a wiki farm, I'm not sure how to it will know which database to update. Instead, do the following:

  • Take a backup of the wiki database
  • Rename the LocalSettings.php file to LocalSettings.php.old
  • Create the config directory and copy the contents over from /var/lib/mediawiki/config/
root@server:~# mkdir /var/www/site.domain.tld/mediawiki/config
root@server:~# cp /var/lib/mediawiki/config/* /var/www/site.domain.tld/mediawiki/config/
root@server:~# chown -R www-data:www-data /var/www/site.domain.tld/mediawiki/config
  • With a browser, visit http://site.domain.tld/mediawiki/index.php and follow the setup instructions. Remember to include the password for the MySQL root user, so the update script can create or modify any tables it needs to.
  • Remove any LocalSettings.php and the copy of the config directory
  • Rename LocalSettings.php.old to LocalSettings.php

Rewriting for Mediawiki 1.7

A historical note, for when the bug in MW 1.11 gets fixed and I forget what worked before the bug! In /etc/apache2/sites-enabled/site.domain.tld:

RewriteEngine on
# Don't rewrite requests for files that really exist or should return 404.
RewriteCond %{REQUEST_URI} !^/favicon.ico
RewriteCond %{REQUEST_URI} !^/robots.txt
RewriteCond %{REQUEST_URI} !^/mediawiki/

# Rewrite http://wiki/article -- this is the main rule
RewriteRule ^/(.*)$ /mediawiki/index.php/$1 [L,QSA]

In LocalSettings.php

$wgArticlePath      = "/$1";
$wgUsePathInfo      = true;

(the last one I'm not sure about, as it wasn't set in MediaWiki 1.7)

See also

Here are a few pages that are useful guides or provide background and context.

Personal tools