Install Mediawiki

From XPUB & Lens-Based wiki

Setting up your own Mediawiki.

Which wiki?

There are many different kinds of wiki softwares around: https://en.wikipedia.org/wiki/List_of_wiki_software

For this page we will focus on installing MediaWiki.

https://www.mediawiki.org/

Where is your wiki?

click and install

Most regular web hosting companies allow for installing MediaWiki without too much trouble, although maintaining and upgrading the code would still in most cases be up to you.

"wiki-family" or "wiki farm"

If you want to run a MediaWiki wiki and don't want to maintain your own infrastructure, you might be interested in a wiki-family or wiki farm.

One of those wiki hosting providers is Fandom (earlier called Wikicities and Wikia), see: https://www.fandom.com/

For more information and a list of wiki farms see: https://www.mediawiki.org/wiki/Hosting_services

on your own server

If you want to install a wiki on your own server, you can follow the steps on this page.

For notes on how to choose what kind of server you would like to work with and how to install it, see: https://pad.xpub.nl/p/hosting-and-serving

Dependencies

Mediawiki requires 3 things to be installed:

  • PHP
  • webserver (like nginx or apache)
  • database (MariaDB, MySQL, SQLite or PostgreSQL)

Check the Mediawiki download page to see which exact versions you need:

https://www.mediawiki.org/wiki/Manual:Installation_requirements

Install a database

For this example we will use MariaDB.

$ sudo apt install mariadb-server

Install a webserver

For this example we will use nginx.

$ sudo apt install nginx

Install PHP

Install PHP + the fpm and php-mysql extension:

$ sudo apt install php php-common php-fpm php-mysql

Configure your webserver to work with the fpm extension.

For example, when you work with nginx, edit the default config file with:

$ sudo nano /etc/nginx/sites-enabled/default.conf

and add the following snippet:

Note: change the version number of php to your installed version!

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

To see if php works now, you can make a php file in /var/www/html/ called test.php:

<?php 

phpinfo();

?>

Now open this file in the browser and see if it works.

Download Mediawiki

Navigate to the folder where you want to install Mediawiki.

In this example we will install it at /var/www/wiki/:

cd /var/www/wiki/

Download the latest version of Mediawiki and unzip the tar file.

You can copy the link from the Mediawiki download page: https://www.mediawiki.org/wiki/Download

wget https://releases.wikimedia.org/mediawiki/1.38/mediawiki-1.38.4.tar.gz
tar xf mediawiki-1.38.4.tar.gz

Rename the wiki folder something short, like "wiki".

mv mediawiki-1.35.1 wiki

Configure the URL

To connect the folder /var/www/wiki/ to an url like https://hub.xpub.nl/soupboat/wiki/ we need to edit the configuration file of the webserver.

$ sudo nano /etc/nginx/sites-enabled/default.conf

Add the following lines:

location /wiki {
    alias /var/www/wiki/;
    index index.php;
}

See if it works: https://hub.xpub.nl/soupboat/wiki/

Database

By default you can log in to MariaDB with the root user and the root password.

However, it's a *good idea* to create a dedicated database + database user for your wiki. In this way you can easily back it up (and eventually restore it) with a simple mysqldump command. Also, it helps to keep different projects separate from each other. See the Mysql page on how to do this. Once you do this add the database name, user name, and password to the Mediawiki setup page when requested.

We will now make a dedicated database for your wiki.

First log in into MariaDB as root:

$ sudo mysql -u root -p

Create a new database:

(Note: replace "<NAMEOFYOURWIKI>" with the name of your wiki, for example: mywiki.)

 CREATE DATABASE <NAMEOFYOURWIKI>;

Create a dedicated user for this database and assign a password.

Write this password down, you will need it later to configure the wiki.

(Note: replace "<USERNAME>" and "<SOMEPASSWORD>" with something else.)

 CREATE USER '<USERNAME>'@'localhost' IDENTIFIED BY '<SOMEPASSWORD>';

Give this user the rights to edit the database:

 GRANT ALL PRIVILEGES ON <USERNAME>.* TO '<USERNAME>'@'localhost'; 
 FLUSH PRIVILEGES;

Exit MariaDB:

 quit

Setup your Mediawiki

Now go to the wiki setup script: https://hub.xpub.nl/soupboat/wiki/

(Or wherever you installed your wiki of course!)

In step 2 you can use your database settings as configured in the above step. The database prefix can be left empty.

Give the wiki a name and fill in the administrator account info. When in doubt, leave things at the default values.

At the end, download the LocalSettings.php file.

Upload LocalSettings.php

Upload the LocalSettings.php file you just downloaded to the folder of your wiki: /var/www/wiki/.

The wiki should work now!

Try it out by opening your wiki: https://hub.xpub.nl/soupboat/wiki/


When installing the wiki on a sandbox server

However for a sandbox server you have to tweak one line in the LocalSettings.php file.

Open the file with a text editor (like nano) and look for:

 $wgScriptPath = "/wiki";

and change it to:

 $wgScriptPath = "/soupboat/wiki";

Enable uploads

Enable uploads in your LocalSettings.php:

 $wgEnableUploads = true; # Enable uploads

and change permissions of the images folder:

$ sudo chgrp www-data /var/www/wiki/images
$ sudo chmod 775 /var/www/wiki/images

From: https://www.mediawiki.org/wiki/Manual:Configuring_file_uploads

You can change the upload size limit in the php.ini file (this is the configuration file for php).

See where it is at the server with:

$ php --ini

Open the php.ini file with nano:

$ sudo nano /path/to/file/php.ini

Search for upload_max_filesize and post_max_size and change the values to your desired upload size, for example to: 32M

Configure

How open/closed do you want your wiki to be?

  • public, everyone can edit
  • public, only people with accounts can edit, account creation is open
  • public, only people with accounts can edit, account creation is closed
  • non-public, only you can edit

...

Back up your wiki

...

Extensions

...

Customizing

Choose a skin

...

Tweaking the skin

You can edit the CSS of the skin at this wiki page: MediaWiki:Common.css

And leave javascript code here: MediaWiki:Common.js

Customize text and menu's

Edit the menu: MediaWiki:Sidebar

Edit system texts: https://www.mediawiki.org/wiki/Help:System_message

See also