MediaWiki Installation on Ubuntu 18.04

Introduction

MediaWiki is a piece of software that helps organize and collect knowledge on a specific topic and put it all into one place. It is great for documentation purposes and is easy to set up. In this guide, we’ll go over how to install it on Ubuntu.

If you need some software that allows you to document, organize, and store information about something, MediaWiki is what you need! It’s super easy to install on Ubuntu 18.04, and we’ve got the whole step-by-step process below.

Versions Used:
Ubuntu 18.04 (Bionic Beaver)
PHP 7.4
MediaWiki 1.35

Prerequisites

Before you install MediaWiki, you need Ubuntu 18.04, and to install the following prerequisites:

sudo apt-get install software-properties-common apache2 mariadb-server -y
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
sudo apt install php7.4 libapache2-mod-php7.4 php7.4-common php7.4-mbstring php7.4-xmlrpc php7.4-soap php7.4-gd php7.4-xml php7.4-intl php7.4-mysql php7.4-cli php7.4-zip php7.4-curl -y

Installing MediaWiki Package

Now we'll need to modify the files and directories within the new Git directory.

wget https://releases.wikimedia.org/mediawiki/1.35/mediawiki-1.35.0.tar.gz
tar -xvzf mediawiki-1.35.0.tar.gz --directory /var/www/
mv /var/www/mediawiki* /var/www/mediawiki
chmod -R 755 /var/www/mediawiki/
chown www-data:www-data /var/www/mediawiki/ -R

Database Initialization

Now we'll need to modify the files and directories within the new Git directory.

We’ll need to set up the MySQL database so that MediaWiki can use it

mysql_secure_installation
Enter current password for root (enter for none): ENTER
Set root password? [Y/n]: ENTER
New password: Enter password
Re-enter new password: Repeat password
Remove anonymous users? [Y/n]: ENTER
Disallow root login remotely? [Y/n]: ENTER
Remove test database and access to it? [Y/n]: ENTER
Reload privilege tables now? [Y/n]: ENTER

Activate the MySQL prompt so that you can create the database and the proper permissions for it. Make sure to replace [change this password] with a password that the MediaWiki software will need to use to login to the MySQL database.

mysql -u root -p
mysql> CREATE DATABASE wikidb;
mysql> GRANT ALL PRIVILEGES ON wikidb.* TO 'wikiuser'@'localhost' IDENTIFIED BY '[change this password]';
mysql> flush privileges;
mysql> exit;

Configuring Packages

Now that we've installed everything through the apt command, we'll need to configure a few of the packages we installed.

We're going to edit a few lines in the PHP configuration file so that the MediaWiki software can run properly. Feel free to make any of these values higher than what we're setting them to. As long as they're set to a value that is greater than or equal to the one below, it should be fine.

vim /etc/php/7.4/apache2/php.ini
file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Chicago

We need to add index.php to the beginning of the DirectoryIndex list like this so that PHP files are looked at before the HTML files:

vim /etc/apache2/mods-enabled/dir.conf

DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.ht

Now we’ll edit the Apache2 site configuration for MediaWiki:

vim /etc/apache2/sites-available/mediawiki.conf

ServerAdmin wiki@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/mediawiki
AllowEncodedSlashes On
ErrorLog /var/log/apache2/mediawiki-error_log
CustomLog /var/log/apache2/mediawiki-access_log combined

Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all

Now we need to enable the configuration file we just created:

a2ensite mediawiki.conf
a2enmod rewrite
a2enmod php7.4
update-alternatives --set php /usr/bin/php7.4
service apache2 restart

Now you should be able to reach the URL of your MediaWiki instance to set it up.

Setting up the Wiki

After configuring all of the prerequisite services and files in the previous steps, we are finally able to set up the MediaWiki software.

If you go to your MediaWiki instance URL, you should get a page that looks like this:

MediaWiki

This error screen is actually not a problem! We’re going to go through a few pages to set the instance up how we want.

Click on the link to “set up the wiki” and it should take you to a page that looks like this:

MediaWiki Installation

We’ll be setting up the Wiki to use English so we can just press “Continue”. This is what the next screen looks like:

MediaWiki Installation

We can just press Continue here. You can resolve most, if not all, of the issues listed in the “Environmental Checks” section but we won’t go over that in this tutorial.

Let’s move on to the next page, “Connect to the database”:

MediaWiki Installation

We’ll need to configure these fields to match the values that we configured earlier when setting up the database. You can see within the screenshot what we configured for our environment as an example.

Now we’ll be taken to a “Database settings” screen:

MediaWiki Installation

We can just press “Continue” here since we don’t want to use a different user for installation.

After this step, we’ll be taken to a page that goes over the naming of the wiki:

MediaWiki Installation

The screenshot above shows how we configured the wiki to use as an example. You’ll need to replace all mentions of “Example” with the name of your wiki. We also selected “I’m bored already, just install the wiki.” since we’re fine with all of the defaults and won’t go over the options that are on the other screens in this tutorial.

After this step, we’re taken to the final “Install” page:

MediaWiki Installation

This is the last chance that you’ll be able to edit any of the values you configured in the previous steps so make sure everything looks good for your setup.

The next screen tells you all the tasks that were completed:

MediaWiki Installation

Since it all looks good, we’ll just press “Continue”.
The next page tells us that we’ve completed the installation!
Well, sort of. We have one more step and that is to install the LocalSettings.php file that it links us to under /var/www/mediawiki/ on the MediaWiki instance.

scp LocalSettings.php example.com:/var/www/mediawiki/
chown root:root /var/www/mediawiki/LocalSettings.php

Now that the configuration file is located under that directory with the proper permissions, you can press “enter your wiki” to be taken to the main page of the MediaWiki instance you just set up!

Now we can move onto installing extensions and skins to your MediaWiki instance for personalization and branding purposes.

Adding Extensions

Since there are many extensions that you can add to your MediaWiki instance, we’ll just go over setting a single extension up so that we can lay out the groundwork. By the end of this, you should be able to apply the same process to other extensions that you might want to add to your MediaWiki instance.

These extensions you can usually find through a quick search on your favorite search engine or you can find them by looking through this page: https://www.mediawiki.org/wiki/Category:All_extensions

For our example, we’ll set up the WikiEditor extension that adds more tools to the editing toolbar when adding to a wiki page.

For the WikiEditor extension, we can find the respective “Extension” page located here: https://www.mediawiki.org/wiki/Extension:WikiEditor

Downloading Extensions

Now that we have the page for the WikiEditor extension, we can find the download link to the extension in the menu on the right side of the page that looks like this:

download extension

Once you press this link, it’ll take you to a menu that lets you select which MediaWiki version you want the extension to support. We’ll select “1.35” which is the latest stable version as of writing this article:

mediawiki extension

Once we’ve chosen our version, press Continue.
It’ll take you to a page that gives you the link to the .tar.gz file and how to extract said file on the command-line.

mediawiki extension

We need to copy the link at the top there and use wget to get it down to our MediaWiki instance:

wget https://extdist.wmflabs.org/dist/extensions/WikiEditor-REL1_35-9bc2d0b.tar.gz -P /var/www/mediawiki/extensions

Now that we have the file on the system, we can extract it using a modified version of the command that the official MediaWiki documentation gave us that includes the file path:

tar -xzf /var/www/mediawiki/extensions/WikiEditor-REL1_35-9bc2d0b.tar.gz -C /var/www/mediawiki/extensions

Now that we have the extension downloaded and extracted, we can move onto installing it.

Installing Extensions

For the WikiEditor extension, we can see how to proceed with installation process by checking the “Installation” section on the official MediaWiki extension page.
For this extension, all that we need to do is add wfLoadExtension( 'WikiEditor' ); to the LocalSettings.php file. So, here’s the quick command on how to do that:

echo 'wfLoadExtension( "WikiEditor" );' >> /var/www/mediawiki/LocalSettings.php

After adding that line to the file, the extension should be installed!

Configuring Extensions

For this specific extension, you can see under the “Configuration” heading on the official MediaWiki extension page that it doesn’t require any other configuration. However, there is the optional configuration to make the new toolbar the default:

echo '$wgHiddenPrefs[] = "usebetatoolbar";
$wgDefaultUserOptions["usebetatoolbar"] = 1;' >> /var/www/mediawiki/LocalSettings.php

NOTE: This step greatly depends on the extension.

Now that we have it configured, we can see the new toolbar when we try to edit a wiki page:

toolbar

Adding Skins

This process is actually quite similar to the steps that are required when adding extensions.

We can few the list of available MediaWiki skins at https://www.mediawiki.org/wiki/Category:All_skins
In this example, we’ll add the Pivot skin.

Downloading Skins

On the official MediaWiki page of the skin, you should see on the right side the same menu we saw for the extension. For this specific skin, we’ll actually want to download it through Git. You can find the link for the git repository URL here:

github

This link will take you to the Git repo for the skin. We’ll want to actually copy the link and use it in a git clone command:

git clone https://github.com/Hutchy68/pivot.git /var/www/mediawiki/skins/Pivot

Now that we have downloaded the repository, we should have everything we need to install the skin.

Installing Skins

For Pivot, we can see that we can install the skin by adding the wfLoadSkin( 'pivot' ); to our LocalSettings.php file.

echo "wfLoadSkin( 'pivot' );" >> /var/www/mediawiki/LocalSettings.php

Now that we have the skin installed, we can configure the skin.

Configuring Skins

We can see that for this specific skin, that there are a few options to configure: https://pivot.wikiproject.net/wiki/Pivot_features
In our example, we’ll change the setting for fixedNavBar to true which would look like this:

echo '$wgPivotFeatures = [
"fixedNav" => true
];' >> /var/www/mediawiki/LocalSettings.php

Our settings should be applied now so you should now be able to go into your user preferences and enable the skin.
If you prefer to set this skin as the default for all users, you replace the line in the LocalSettings.php file like this:

sed -i 's/\$wgDefaultSkin.*/\$wgDefaultSkin = "pivot";/g' /var/www/mediawiki/LocalSettings.php

After changing your skin, you should be able to see your MediaWiki instance with the new theme!

example wiki

Conclusion

MediaWiki is easy to set up on Ubuntu 18.04, and it’s also very customizable thanks to the user-friendly skins. However, If you have any questions during installation, or about the skins, just contact us and we’d love to make sure you get it up and running asap!

Leave a Comment