MediaWiki: upgrade, extensions and self-hosted install
Upgrade MediaWiki with rclone, add extensions, install on your own server with Nginx and certbot, plus maintenance tasks.
This article describes how to upgrade a self-hosted MediaWiki by unpacking the new release next to the current one, adding extensions, reusing LocalSettings.php and syncing the result to the web root. It also covers a local installation (database, permissions, HTTPS) and a few maintenance tasks.
Before you start
- Make a full backup of the files and the database first (for example with your own
backup_wiki.sh). - Check the installed version on the
Special:Versionpage of the wiki. - Keep a copy of the current
LocalSettings.php.
Download the release and the extensions
Work in a temporary folder.
cd ~/tmp
curl -o mediawiki.tar.gz https://releases.wikimedia.org/mediawiki/1.45/mediawiki-1.45.3.tar.gz
tar -xvf mediawiki.tar.gz
Extensions bundled with a given release branch are downloaded from Special:ExtensionDistributor. Pick the extension and the branch matching your MediaWiki version; the page gives the tarball URL. Then:
curl -o MobileFrontend.tar.gz "<URL given by ExtensionDistributor>"
tar xvf MobileFrontend.tar.gz -C mediawiki-1.45.3/extensions
Repeat for each extension in use. The extensions used in this setup were:
| Extension | Purpose |
|---|---|
| MobileFrontend | mobile skin |
| CategoryTree | category navigation |
| intersection (DynamicPageList) | list pages by category |
| UserMerge | merge user accounts |
| Babel, cldr, CleanChanges, Translate, UniversalLanguageSelector | multilingual wiki (see Translate installation) |
Reuse the configuration
cp /usr/share/webapps/wiki/LocalSettings.php ~/tmp/mediawiki-1.45.3/
Deploy the new version
Check what would change first with --dry-run, then run for real and fix ownership:
sudo rclone sync ~/tmp/mediawiki-1.45.3 /usr/share/webapps/wiki/ --dry-run --verbose
sudo rclone sync ~/tmp/mediawiki-1.45.3 /usr/share/webapps/wiki/ --verbose
sudo chown -R wiki:wiki /usr/share/webapps/wiki/*
On a remote host the same sync can target a remote:
rclone sync mediawiki-1.45.3 wiki:/public_html/ --progress --transfers 8 --checkers 16 --buffer-size 64M --multi-thread-streams 8
Another approach is to keep versioned folders and switch a symbolic link:
cd new
rm current
ln -s ./mediawiki-1.45.3 current
Run the web updater
Open https://wiki.example.com/mw-config/ and enter the upgrade key found in LocalSettings.php ($wgUpgradeKey). Follow the pages to completion.
During the check, the installer may warn that the default upload directory is vulnerable because it can execute scripts. MediaWiki validates uploaded files, but you should still disable script execution in the upload directory before enabling uploads. The environment check also reports whether the PHP intl extension is used for Unicode normalisation.
Change the logo
Upload the logo files to resources/assets (for example through SFTP), then edit LocalSettings.php:
$wgLogos = [
'1x' => "$wgResourceBasePath/resources/assets/mylogo.128.png",
'icon' => "$wgResourceBasePath/resources/assets/mylogo.128.png",
];
Edit the sidebar
The sidebar is the wiki page MediaWiki:Sidebar, edited with index.php?title=MediaWiki:Sidebar&action=edit.
Install on your own server
Database
CREATE DATABASE dbwiki;
CREATE USER uwiki IDENTIFIED BY '<PASSWORD>';
GRANT ALL PRIVILEGES ON dbwiki.* TO 'uwiki'@'%';
FLUSH PRIVILEGES;
Matching settings in LocalSettings.php:
$wgDBtype = "mysql";
$wgDBserver = "localhost";
$wgDBname = "dbwiki";
$wgDBuser = "uwiki";
$wgDBpassword = "<PASSWORD>";
$wgDBprefix = "";
$wgDBTableOptions = "ENGINE=InnoDB, DEFAULT CHARSET=binary";
Test the login:
mysql -h localhost -u uwiki -p dbwiki
Folders and files
sudo mkdir /var/lib/wiki
sudo chown wiki:wiki /var/lib/wiki
sudo mkdir /usr/share/webapps/wiki
sudo cp -r ~/tmp/mediawiki-1.45.3/* /usr/share/webapps/wiki/
sudo chown -R wiki:wiki /usr/share/webapps/wiki/*
Restore the database from a backup
zcat db_backup.sql.gz | mysql -u uwiki -p
HTTPS with Nginx
sudo certbot --nginx --agree-tos --redirect --staple-ocsp --email admin@example.com -d wiki.example.com
Maintenance
Run a maintenance script as the web user (since MediaWiki 1.40 scripts are started through run.php):
sudo su wiki
/usr/bin/php /usr/share/webapps/wiki/maintenance/run.php refreshLinks
Purge the cache of one page:
https://wiki.example.com/index.php/Home?action=purge
Mount the remote site over SSH
sshfs lets you browse the hosting account like a local folder:
sudo mkdir /mnt/wiki
sudo chmod 755 /mnt/wiki
sudo sshfs -o allow_other,default_permissions user@example.com:~/ /mnt/wiki
# unmount
sudo umount /mnt/wiki
Without root, use sshfs -o idmap=user,allow_other,default_permissions user@example.com:~/ mnt/wiki.
Notes
- Never publish the upgrade key, database password or SMTP password; they live in
LocalSettings.php. - Always run
rclone sync --dry-runfirst:syncdeletes destination files that are absent from the source. - Upgrade one release at a time when skipping several versions is not supported by the release notes.