Setting Up MediaWiki on AWS

From Humanoid Robots Wiki
Revision as of 18:31, 21 May 2024 by Ben (talk | contribs) (Enabling LaTeX)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This document contains a walk-through of how to set up MediaWiki on AWS. In total, this process should take about 30 minutes.

Getting Started[edit]

  1. Use this service to install MediaWiki to an EC2 instance
  2. After installing, SSH into the instance. The MediaWiki root files live in /var/www/html, and Apache configuration files live in /etc/apache2

Set up A Record[edit]

In your website DNS, create an A record which points from your desired URL to the IP address of the newly-created EC2 instance. For example:

  • Host name: @ (for the main domains) or wiki (for subdomains)
  • Type: A
  • Data: 127.0.0.1 (use the IP address of the EC2 instance)

Installing OpenSSL[edit]

Roughly follow these instructions to install OpenSSL using LetsEncrypt

  1. Install certbot
sudo apt install certbot python3-certbot-apache
  1. Run certbot (you can just select "No redirect"
sudo certbot --apache
  1. Verify certbot
sudo systemctl status certbot.timer

Update Page URLs[edit]

To get MediaWiki to display pages using the /w/Some_Page URL, modify LocalSettings.php. Replace the line where it says $wgScriptPage = ""; with the following:

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

Next, in /etc/apache2/apache2.conf, add the following section:

<Directory /var/www/html>
        AllowOverride all
</Directory>

Create a new .htaccess in /var/www/html with the following contents:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^w/(.*)$ index.php/$1 [PT,L,QSA]

Finally, reload Apache2:

sudo service apache2 reload

Extras[edit]

Here are some notes about some extra features you can add on top of MediaWiki.

Storing images in S3 with Cloudfront[edit]

You can use the AWS MediaWiki Extension to allow users to upload images and files, store them in S3, and serve them through CloudFront.

This process is somewhat involved. I may write notes about how to do this well in the future.

Enabling LaTeX[edit]

  • Install the REL1_31 branch of the Math extension to the extensions directory
sudo git clone -b REL1_31 --single-branch --depth 1 https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
  • Enable the extension in LocalSettings.php
wfLoadExtension('Math');
  • Run the update script
sudo php maintenance/update.php