MediaWiki system administration

This page contains some notes about the system administration of a MediaWiki web server for a small-ish and low-traffic wiki.

Setting up a new server

For a normal upgrade, it's possible to have the old VPS available for comparison while setting up the new one, but it should be possible to restore only from backups.

sudo update-alternatives --config editor

Apache

The default log format is not all that great, so change it to something more greppable and with only the info we want. The format codes used here explained below.

LogFormat "%h %t %v%U%q %>s \"%{Referer}i\" \"%{User-agent}i\" sec:%T" mediawikiformat
CustomLog ${APACHE_LOG_DIR}/access.log mediawikiformat
  • %h Remote hostname or IP address
  • %h Date and time
  • %v ServerName (as defined in the relevant VirtualHost section)
  • %U URL path (with a leading /)
  • %q Query string (with a leading ?)
  • %>s The final HTTP status code
  • \"%{Referer}i\" The Referer header
  • \"%{User-agent}i\" The User-agent header
  • sec:%T Number of seconds taken to serve the request

MediaWiki

Install from tarball to /var/www/mediawiki, then install extensions with Composer.

Cronjobs

MAILTO=admin@example.org
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# MediaWiki statistics.
@weekly /usr/bin/php /var/www/mediawiki/maintenance/run initSiteStats --wiki=mywiki --active --update

# Sitemaps
@weekly /usr/bin/php /var/www/mediawiki/maintenance/run generateSitemap --fspath /var/www/mediawiki/sitemaps --urlpath /sitemaps/ --wiki mywiki --identifier example.org --server https://example.org

# Update query pages
@weekly /usr/bin/php /var/www/mediawiki/maintenance/run updateSpecialPages --wiki mywiki

# Database backups
@daily /var/backups/bright/backup.sh

Mail

The msmtp package is pretty useful. Install it and set it up in /etc/msmtprc:

defaults
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt

account default
auth on
host smtp.fastmail.com
port 587
user mainuser@fastmail.com
from wiki@example.org
password ThisIsAnAppPassword123

aliases /etc/aliases