MediaWiki with nginx on Linode

This page is really old. I recently installed MediaWiki again for a different project, and wrote more detailed instructions.

Preventing spam

Append the following lines to your LocalSettings.php before uploading it to production. This will prevent user registration and anonymous editing, i.e., you’ll be the only one able to make any changes.

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

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

Rewriting URLs

By default, MediaWiki uses the /index.php?title=Page_name syntax for articles. But this is ugly, so it’s better to use rewrite rules in nginx to change this to /wiki/Page_name like on Wikipedia.

In some place nginx can read1:

# Modified from
location / {
    index index.php index.php5;
    error_page 404 = @mediawiki;

location @mediawiki {
    rewrite ^/wiki([^?]*)(?:\?(.*))? /index.php?title=$1&$2 last;

In LocalSettings.php:

# From
$wgScriptPath       = "";
$wgArticlePath      = "/wiki/$1";
$wgUsePathInfo      = true;


Below I’ll outline steps to get both the image-style rendering of math and Mathjax to work on Mediawiki.

First create an uploads directory in your MediaWiki directory. Make sure www-data owns this. Install texvc as instructed on MediaWiki’s documentation page. You might also need to change the permissions of the images directory.

# For math
require_once "$IP/extensions/Math/Math.php";

$wgUploadDirectory = "/var/www/cp_mediawiki/public_html/uploads";
$wgUploadPath = "/uploads";

$wgTexvc = "/usr/bin/texvc";

$wgMathValidModes[] = MW_MATH_MATHJAX; // Define MathJax as one of the valid math rendering modes
$wgUseMathJax = true; // Enable MathJax as a math rendering option for users to pick
#$wgDefaultUserOptions['math'] = MW_MATH_MATHJAX; // Set MathJax as the default rendering option for all users (optional)
#$wgDefaultUserOptions['mathJax'] = true; // Enable the MathJax preference option by default (optional)
$wgMathDisableTexFilter = true; // or compile "texvccheck"

If you want to modify the MathJax settings, you’ll have to go change includes/OutputPage.php, as explained in this answer.

In my case, I changed the relevant part to:

$ret .= $this->buildCssLinks();

$ret .= "<script type='text/x-mathjax-config'>MathJax.Hub.Config({
    // TeX font has better spacing on Linux browsers
    availableFonts: ['TeX'],
    preferredFont: 'TeX'

$ret .= $this->getHeadScripts() . "\n";

cite web

Quite surprisingly, I could find almost nothing on the internet about installying the very useful cite web template. The best I could find was a Yahoo Answers page from 2009, which proved to be at least somewhat helpful. I’ll provide the full steps.

As noted, you have to install ParserFunctions. In addition, I found that you need Scribunto to process the Lua code that cite web apparently uses.

Now, go to Wikipedia’s Special:Export page, and export the following (make sure you check “Include templates” at the bottom, so that it pulls in dependencies2) and save to a file:

Template:Cite web
Module:Citation/CS1/Date validation

Now go to your own wiki’s Special:Import page. In my case, this was at Now browse for the file you just exported from Wikipedia, and click “Upload file” to import everything.

With any luck, cite web should now work!3

  1. In the case of the Cause Prioritization Wiki, which was the reason I installed MediaWiki, this was stored in /etc/nginx/sites-available/ (with a symbolic link to the sites-enabled counterpart). The full file is as follows:

    server {
        listen 80;
        listen [::]:80;
        root /var/www/cp_mediawiki/public_html;
        index index.php index index.html;
        # Modified from
        location / {
            index index.php index.php5;
            error_page 404 = @mediawiki;
        location @mediawiki {
            rewrite ^/wiki([^?]*)(?:\?(.*))? /index.php?title=$1&$2 last;
        # Modification of
        location ~ \.php$ {
            try_files $uri =404;
            include /etc/nginx/fastcgi_params;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /var/www/cp_mediawiki/public_html$fastcgi_script_name;
        access_log /var/www/cp_mediawiki/log/access.nginx.log;
  2. Or at least that’s what I think it does.

  3. In my case it wasn’t so simple: at first, I got a Lua error in package.lua at line 80: module 'Module:Citation/CS1/Configuration' not found. error even though I had already installed Module:Citation/CS1/Configuration! It turned out though that when logged out, cite web worked fine. I ended up editing the page once, and that seemed to make the page finally re-render.