Install MediaWiki On Ubuntu 17.04 Zesty Zapus

Wikipedia, that encyclopedia of a thousand “citations needed”, runs on an open-source web application called MediaWiki. A wiki, if you haven’t heard the term before, is basically an online encyclopedia that relies on user contributions. Wikis can range from broad, general-topic encyclopedias like Wikipedia itself, or devoted to a single topic, like a television show or a computer game. You can quite easily install MediaWiki and host your own wiki off a Ubuntu system. Installing MediaWiki on Ubuntu 17.04 Zesty Zapus takes three steps: first, you install the prerequisite software packages, second, you configure the prerequisites, and third, you install MediaWiki and run its configuration script.

Let’s begin!

First, install Ubuntu into your machine of choice. Once Ubuntu is installed and updated, you will need to install five pieces of software: the Apache web server, the MySQL database server version 5.7, PHP version 7, the MySQL module for PHP, and finally the MediaWiki software itself.

First, install the Apache web server. To install Apache, go to a Terminal window or a command prompt and type this command:

sudo apt-get install apache2

(Technically, you’ll be installing Apache 2, the latest version.)

Enter your password to authenticate, follow the default prompts, and apt will download and install the Apache web server for you.

And that’s it! Apache should now be working. To test it from the web server itself, go to a web browser and visit the address You’ll remember that this is the “local loopback” address, basically the address the computer uses to refer to itself. Alternatively, you could test it from another computer on the same subnet. For instance, if you installed Apache on a computer with an IP address of, you could test it by going to another computer on the same subnet and visiting http://192.168.100 from the web browser.

Regardless, if Apache is working properly, you should see the default Apache/Ubuntu web page with the Ubuntu logo in the upper left-hand corner.

Apache is now operational.

The next step to install MediaWiki is to install the MySQL database server. Return to the Terminal and type this command:
sudo apt-get install mysql-server-5.7

(As of this writing, MySQL Server version 5.7 is the latest version available in the Ubuntu repositories, though future versions of Ubuntu may receive the newer versions of MySQL.)

Enter your password to authenticate, and apt will download the MySQL files and install them for you. It’s a big set of files, so depending on the speed of your Internet connection, it might take a while to download. After the files are downloaded and are installing, the installer will ask you for a password for MySQL’s root user. Just as the root user in Linux has complete control over the system, the root user in MySQL has absolute control over all databases, tables, permissions, and users. For obvious security reasons, you’ll want to create an extremely strong password (a mixture of uppercase, lowercase, numbers, and punctuation, the longer the better) for your MySQL root user.

(Note that in the password dialog box, if you can’t get the <OK> field selected, you can use the tab key to jump from the text input line to the <OK> field.)

After you enter the root password, the installer will finish working with the MySQL files, and return you to the command line.

Next, you’ll want to run the mysql_secure_installation script to tighten up security on your new MySQL server. Run this command from the prompt:

sudo mysql_secure_installation

First, the mysql_secure_installation script will ask you to enter the current password for the MySQL root user. After you do that, it will ask if you want to change the root password. Since you already set a root password, you can hit “n” (unless you want to change it again for some reason).

Next, the script will ask you to setup the VALIDATE PASSWORD plugin, which checks passwords for appropriate strength. Hit Y to accept, and then set the password strength level by hitting 0 for Low, 1, for Medium, and 2 for Strong.

Next, the script will ask if you want to remove the anonymous user. The anonymous user, like anonymous access in FTP, lets someone log into MySQL without having a proper user account. For security reasons, it’s always best to remove the anonymous user, so hit “y” to continue.

After that, the script will ask if you want to prevent the MySQL root user from logging in remotely to the MySQL server. Always hit “y” to forbid root remote access, since if an attacker guesses your root password, he can destroy your databases or steal the information they contain.

After this, the script will ask if you want to remove the test database. MySQL includes a test database that anyone can access. Again, this is a security hole, so you’ll want to hit “y” to remove the test database.

The script will then ask to reload the privilege tables so the changes take effect. Hit “y”, and the mysql_secure_installation script will conclude and return you to the command line.

MySQL server is now installed on your Ubuntu system.

The next step to installing MediaWiki is to install PHP version 7:

sudo apt-get install php

Then install the MySQL module for PHP:

sudo apt-get install php-mysql

Then install the mbstring PHP module:

sudo apt-get install php-mbstring

Then install the xml PHP module:

sudo apt-get install php-xml

Next, restart Apache with this command so that it reloads with all the PHP extensions enabled:

sudo /etc/init.d/apache2 restart

Finally, download the MediaWiki software to your Desktop. You can obtain it from this address:

If you’re working exclusively from the command line, you can use this command to download the MediaWiki software:


(Note that the version number, and hence the file name, WILL change with future versions of MediaWiki, so double-check before downloading the file.)

Use this command to unpack the MediaWiki files:

tar -xzvf mediawiki-1.27.1.tar.gz

Finally, move the MediaWiki files over to the /var/www/html directory. (In this command, I’ll assume you unpacked the MediaWiki files to your home directory; you will have to adjust the command if you unpacked them in a different directory.)

sudo cp -r ~/mediawiki-1.27.1/* /var/www/html

Now we’ll need to prepare MySQL for use with MediaWiki. MediaWiki requires a database and a database user, and full permission for its database user to access its database. To start the MySQL command-line client, use this command:

mysql -u root -p

Enter the password for the MySQL root user, and you’ll find yourself at the MySQL command prompt, which will look like this:


Our next steps are to create a MediaWiki database, create a user to access that database, and grant our new user all rights to the MediaWiki database.

(An important note before we continue, though. All commands made from the MySQL prompt must end with a semicolon to denote the end of the statement. Any commands that do not end with a semicolon will not work. With that in mind, let’s first create a database.)

To create a database for MediaWiki, use this command at the mysql> prompt:


The MySQL client will respond with a message that should say “Query OK, 1 row affect (0.00 sec).” This means the command was successful, and a new database named “newdatabase” has been created.

Next, you’ll create a user who will access that database and assign a password to that user. In this example, we’ll assign a password of “1234”. However, in real life, just as with the root user, you’ll want to assign a strong password. (This database user won’t have full control over the MySQL user as the root user does, but we will give it full control over the database we just created, and a malicious user who guesses the password could cause all kinds of trouble.):

CREATE USER mediawikiuser IDENTIFIED BY ‘1234’;

Again you should get the “Query OK” confirmation message. The final step is to assign all privileges on the “mediawiki” database to the “mediawikiuser” user. Use this command to assign the permissions:

GRANT ALL PRIVILEGES ON mediawiki.* TO mediawikiuser IDENTIFIED BY ‘1234′;

That isn’t a typo – those are single quote marks (‘) instead of the usual double quote marks (“) that were used in the command to set the password. MySQL’s internal syntax, alas, isn’t always consistent. Anyway, if you typed the command correctly, you should get the “Query OK” confirmation again.

Once you are done, use this command to quit the MySQL command-line interface:


Once is this is done, rename Apache’s default index.html file to index.html.old. Otherwise Apache will access the default sample page instead of starting WordPress:

sudo mv index.html index.html.old

Once the permissions have been set, launch the installation script by navigating here in your Ubuntu system’s web browser:

The installation script is simply a web form you’ll need to fill out. The default settings will work for the most part. You’ll need to pick a name for your wiki, and you’ll also need to enter the database name, the database user, and the password you created for MySQL. You will also need to set an administrator username and password for the wiki. Once you have appropriate information entered, complete the script, and MediaWiki will be installed.

However, you’ll need to do one more thing to finish the installation. After you complete the install script, MediaWiki will generate a LocalSettings.php file and offer it to you for download. Make sure to download the file and then transfer it to the /var/www/html file in order to complete the installation. (You may need to use SSH and SFTP to do this – see Chapter 10 on how to set them up.)

MediaWiki should now be functioning on your Ubuntu system.
Was this post helpful? These books might be useful: