Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Instructions and sample configuration for setting up MediaWiki on nginx on Ubuntu 16.10

These instructions were written in the process of setting up the timelines wiki.

Full list of software:

  • Ubuntu 16.10
  • nginx
  • MediaWiki
  • MediaWiki extensions
  • MediaWiki templates
  • php7.0-fpm
  • certbot (letsencrypt)
  • Linode for domain stuff


Set up the system

As root:

apt update
apt upgrade
apt install lynx # useful later for configuring MediaWiki

Set up nginx, php-fpm, and MySQL

As root:

apt install nginx
apt install php-fpm php-mysql php-mbstring php-xml
systemctl restart php7.0-fpm
apt install mysql-server

Configure MySQL:

mysql -u root -p
create database timelines;
# do more stuff

DNS stuff

On Linode's DNS manager, add a new subdomain for, and make sure to point it to the new instance. Also on the new Linode instance, set up reverse DNS. Note that even if you do everything right, there will be a delay until the domain starts working, so don't panic.

Install MediaWiki

We will be installing MediaWiki at /var/www/timelines/. Modified from the instructions on the MediaWiki manual (note that the official Ubuntu guide is for Apache, and here we're using nginx):

mkdir /home/issa/Downloads
cd /home/issa/Downloads
tar xvzf mediawiki-1.28.0.tar.gz
mv mediawiki-1.28.0 /var/www/timelines

Now do lynx http://localhost/index.php to fill in the web form to complete the installation. The setup instructions on the MediaWiki site are pretty detailed, and it pretty much goes as expected.

TODO talk about permissions for the files in the mediawiki archive.

Set up HTTPS support

Instructions are modified from the official instructions.

As root:

apt install letsencrypt
letsencrypt certonly --webroot -w /var/www/timelines -d
letsencrypt renew --dry-run --agree-tos
vim /etc/crontab # add '0 0 1 * * root letsencrypt renew'
vim /etc/nginx/sites-available/default

Now in /etc/nginx/sites-available/default add a new block to redirect all HTTP connections to HTTPS:

server {
        listen 80;
        listen [::]:80;
        return 301 https://$host$request_uri;

In the regular server block, change the port and give an SSL certificate:

server {
        listen 443 ssl default_server;
        listen [::]:443 ssl default_server;
        ssl_certificate /etc/letsencrypt/live/;
        ssl_certificate_key /etc/letsencrypt/live/;


MediaWiki extensions

The first three of the following MediaWiki extensions are required for correctly rendering wikitext copied from the English Wikipedia. This is because the English Wikipedia uses various templates and extra tags. Google Analytics is a personal preference but is not required for rendering content. MobileFrontend is to make the appearance better on mobile devices, but is not required.

The setup for these is pretty straightforward: download the tarball, extract it to the correct location, and add a few lines in LocalSettings.php. I'll just link to the official documentation because I have nothing to add.

MediaWiki imports

MediaWiki's instructions specifically say to 'Uncheck the box "Include only the current revision, not the full history".' However I find that unchecking this returns a very old version of the page for at least one page (MediaWiki:Common.css). I have no idea why this is, but one remedy is to export both with this box checked and with this box unchecked. You can always run php rebuildrecentchanges.php in the maintenance directory to deduplicate revisions, so I'm pretty sure importing twice is fine. (Note: I began by trying to import the XML dump with the "full history" so I have no idea what happens if you only try to get the most recent version.)

The MediaWiki instructions linked above is fine for step 1. But since we're exporting from the English Wikipedia, go to Special:Export on that wiki instead. As for step 2, I found Special:Import to be unreliable because the connection kept resetting, so I used importDump.php in the MediaWiki maintenance directory instead.

List of pages I exported:

Template:Spaced en dash
Template:Technology company timelines
Template:Cite journal
Template:Cite web
Template:Cite press release
Template:Cite book
Template:Use mdy dates
Template:Cite conference
Template:As of
Template:See also
Template:Yahoo! Inc.
Template:Update inline
Template:Verify source
Template:Dead link
Template:Tesla Motors
Template:Interlanguage link
Template:Key press
Template:Cite patent
Template:US patent
Template:Cite newsgroup
Template:Timelines of computing
Template:Cancer timeline
Template:Authority control
Template:Inconsistent citations
Template:Respiratory pathology
Template:Viral diseases
Template:Citation needed
Template:Cite encyclopedia
Template:End div col
Template:Single double
Template:Double single

Here is an example of an importing process:

cd /var/www/timelines/maintenance
php importDump.php < /home/issa/Wikipedia-20170312181023.xml
php rebuildrecentchanges.php

Interwiki links

NOTE: Newer versions of MediaWiki come with the Interwiki extension. You will need to add two lines to LocalSettings.php after which you can add interwiki links from Special:Interwiki/add. Alternatively use the database instructions below.

You will need to log in to the database for this.

The example on the MediaWiki documentation is slightly outdated.

Log in:

mysql -u your_username -p
# enter password

From the MySQL prompt, add the interwiki links:

insert into interwiki (iw_prefix, iw_url, iw_local, iw_trans, iw_api, iw_wikiid)

Other wikis to consider:

  • LessWrong Wiki
  • Bitcoin Wiki (which one?)

Reference tooltips

Reference tooltips are the the hover-over popups that show up when you hover over a reference superscript. If you used the MediaWiki imports above then this will already be included. However if you didn't include reference tooltips in your imports, then this is another way to do the same thing.

To get reference tooltips for your wiki, here are the steps:

Upgrading to Ubuntu 17.10

When I originally wrote this page, the latest version of Ubuntu was 16.10. The latest version now is Ubuntu 17.10. One difficulty with the upgrade here is that MediaWiki 1.28 (or one of the extensions) is incompatible with php7.1-fpm, which comes with Ubuntu 17.10. To get around this, I upgraded to MediaWiki 1.29.2 (along with all of the extensions).

The MediaWiki upgrade process was rather straightforward. I referred to the following references while performing the upgrade:

For juggling the directories in /var/www, I did the following:

  • Stop nginx
  • Set up the new MediaWiki directory in /var/www/timelines-new
  • Move /var/www/timelines to /var/www/timelines-old
  • Move /var/www/timelines-new to /var/www/timelines

I copied LocalSettings.php and images/. I did not copy over any extensions, choosing instead to just install them again.

The suggested commands for changing permissions of the images/ directory (find ./images -type d -exec chmod 755 {} \; and chgrp -R www-data images) might not be enough. I found that I was unable to upload any images ("Could not open lock file" etc.). To fix this, I also had to run chown -R www-data:www-data images.

Upgrading to Ubuntu 18.04

Ubuntu 18.04 has PHP 7.2 as the default, but MediaWiki does not yet support this version of PHP. It's supported starting MediaWiki version 1.31, but 1.31 is apparently not yet an official release.

So what I did was keep the current version of MediaWiki and use a PPA to install PHP 7.1 again:

Then in the nginx config, I just specified that PHP 7.1 should be used (which should have been the case already, since PHP 7.1 was the version before the upgrade).


Instructions and sample configuration for setting up MediaWiki on nginx on Ubuntu 16.10+



No releases published


No packages published