Host your own wiki

How to… Install Mediawiki on a Amazon Lightsail hosted Ubuntu virtual private server with Nginx and MySQL.

This guide will explain how to create your own wiki, capable of handling a few thousand concurrent users, without needing any specialist skills or hardware. It will run on a cloud computing Virtual Private Server, have Ubuntu 18.04 as the operating system, Nginx as the webserver, and Mediawiki 1.3.1 as the content management system.

Amazon Web Services (AWS) has been chosen here because of the amount of data transfer they include in their Lightsail plans which would otherwise cost significantly more at another provider or if you used an EC2 instance. Providers such as Google Cloud Computing and Digital Ocean, among others supply comparable services that work in a similar way.

Step 1

Chose a name for your wiki, then go to a domain registrar of your choice and purchase a domain name.

You do not need ssl certificates, web hosting, email, or any of the other offers they will try and get you to buy at the same time. You may however want privacy protection.

Step 2

Go to Amazon Web Services (AWS) and sign up for an account, verify payment details, your email, and fill in all the things they ask for. Make sure your account is complete and active before continuing.

Step 3

Navigate to the Amazon Lightsail product in your AWS console. Make sure you are logged in.

You will now configure your Lightsail assets; first, you will create a DNS Zone for your domain.

      1. Choose the Networking tab, and then choose Create DNS zone.


      1. Enter your registered domain name, such as, into the text box. It isn’t necessary to include www when entering your domain name. You can add the www using an address (A) record later on. Or not bother with the prefix at all.


    1. Choose Create DNS zone, then check it has been created.



Note the Lightsail name servers that are then listed; there will be four nameserver addresses which you must then put in to the relevant domain settings at your domain registrar.

Exactly how you change the nameservers at your registrar varies according to which service your chose, they will have instructions on how this is done.

This has been done first because it often takes a long time for DNS nameserver settings to be updated.

Step 4

You will now setup an instance, and assign a static IP address to it.

Then, connect to your instance via SSH. On linux you can do this as follows:

$ ssh -i "/path/to/keyfile.pem" ubuntu@<server-ip>

If you want to setup non-root users or additional access controls, this is the time to do it. (not detailed in this guide)

Step 5

Start with updating the apt so you can download stuff;

$ sudo apt update

Then install nginx;

$ sudo apt install nginx

And install ufw (a firewall);

$ sudo apt install ufw

and enable two firewall rules:

$ sudo ufw allow 'Nginx full'
$ sudo ufw allow 'OpenSSH'

If you don’t enable OpenSSH correctly you will brick your instance when enabling the firewall. “Nginx full” allows both http and https traffic to your webserver.
Now enable the firewall and check it’s status.

$ sudo ufw enable
$ sudo ufw status

Status should output something like:

Status: active
To Action From
-- ------ ----
Nginx Full ALLOW Anywhere 
OpenSSH ALLOW Anywhere 
Nginx Full (v6) ALLOW Anywhere (v6) 
OpenSSH (v6) ALLOW Anywhere (v6)

In the lightsail console, enable https in the settings under the networking tab, this is a firewall as well, an additional firewall to ufw.

Using the systemctl status checker, see if nginx is active and working;

$ systemctl status nginx

Navigate to http://<your server ip> to make sure the nginx welcome screen is accessible. Please note that https will not work yet because it is not configured.

Step 6

Now download mediawiki, check for an up-to-date download link, unzip it, and delete the orginal zip file.

$ wget
$ tar xvzf mediawiki-1.31.1.tar.gz
$ rm mediawiki-1.31.1.tar.gz

Create a root webserver directory:

$ sudo mkdir -p /var/www/html/mediawiki/

And move the mediawiki directory into it, renaming the directory “w”;

$ sudo mv mediawiki-1.31.1/ var/www/html/mediawiki/w/

Step 7

Now we install php 7.2, and all the php stuff mediawiki needs;

$ sudo apt install php7.2-common php7.2-cli php7.2-intl php7.2-fpm php7.2-apcu php7.2-mysql php7.2-mbstring php7.2-xmlAnd check it;

$ php -v
$ sudo systemctl status php7.2-fpm

Open the nginx conf;

$ sudo vi /etc/nginx/sites-enabled/default

Add the following;

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;

And change the root to “/var/www/html/mediawiki/” and add “index.php” to the list of index pages.

Press “Esc” :wq “Enter” to save using vi.

Check the syntax with:

$ sudo nginx -tAnd create the following;

$ sudo vi /var/www/html/mediawiki/info.php

With the content;


Then restart nginx,

$ sudo systemctl restart nginxAnd navigate to http://<server ip>/info.php
You should see your php configuration, save a copy of this page.

Then delete this php access for security;

$ sudo rm /var/www/html/mediawiki/info.php

Step 8

In this step, you install a free ssl certificate from letsencrypt.

$ sudo apt updateNow install certbot;

$ sudo apt-get install python-certbot-nginxAnd use certbot, selecting option 2 for http to https redirect when prompted.

$ sudo certbot --nginx -d <domain name>Your ssl certificate will now be generated and installed. Please note this will need to be renewed every three months, please see letsencrypt website for details on how to automate this.

Step 9

Now install a database

$ sudo /usr/bin/mysql -u root mysql
MariaDB [mysql]> $ create database wiki;
MariaDB [mysql]> $ CREATE USER 'wiki-user'@'localhost' IDENTIFIED BY 'secure123';
MariaDB [mysql]> $ GRANT ALL PRIVILEGES ON *.* TO 'wiki-user'@'localhost';
MariaDB [mysql]> $ FLUSH PRIVILEGES;
MariaDB [mysql]> $ show grants for 'wiki-user'@'localhost';
This will create a database called wiki, and a new user called “wiki-user” with the password “secure123”, the new user will have root access

now to install mediawiki: navigate to http://<server-ip>/w/mw-config/index.php and follow the installation wizard, make sure to download the LocalSettings.php file it generates.

Open the file in a text editor on your local computer, then create a file as folows:

$ sudo vi /var/www/html/mediawiki/w/LocalSettings.phpAnd copy and paste the contents in the new file on your server, and then save.

Now visit your new wiki! 

Step 10

(optional configuration)

To install an extension, like proofread page shown here;

$ sudo apt-get install git
$ cd /var/www/html/mediawiki/w/extensions/
$ sudo git clone -b REL1_31
$ mv mediawiki-extensions-ProofreadPage/ ProofreadPage/
And add wfLoadExtension( 'ProofreadPage' ); to the LocalSettings.php file;

and run:

$ sudo php maintenance/update.phpYou can find more at and install them with the same basic procedure and configure them as defined in the documentation at

to import a dump, download it with wget, then run:

sudo php /var/www/html/mediawiki/w/maintenance/importDump.php --conf /var/www/html/mediawiki/w/LocalSettings.php dumpfile-oldwebsite-full.xml

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.