Categories Tutorials

How to install MediaWiki on an Ubuntu 16.04 VPS

In this tutorial we are going to provide you with step by step instructions on how to install MediaWiki on an Ubuntu 16.04 VPS. MediaWiki is an open-source wiki software written in PHP.

At the time of writing this tutorial, the latest stable version of MediaWiki is 1.27.1 and it requires:

  • PHP 5.5.9 or higher (preferably the latest), with mbstring, JSON, curl, Intl, mysql and GD PHP extensions enabled. ImageMagick or GD is required for image thumbnailing
  • MySQL 5.0.2, MariaDB 5.1, SQLite 3 or PostgreSQL 9.0 or later
  • Apache web server 2.0 or higher compiled with mod_rewrite module.

This install guide assumes that Apache is already installed and configured on your virtual server.

Let’s start with the installation. Make sure your server OS packages are fully up-to-date:

apt-get update 
apt-get upgrade

Install the required packages:

apt-get install imagemagick php7.0-intl php7.0-curl php7.0-gd php7.0-mbstring php7.0-mysql

Enable Apache rewrite module if it is not already done so:

a2enmod rewrite

Restart the Apache service for the changes to take effect:

service apache2 restart

Install MediaWiki

Download the latest version of MediaWiki available at https://www.mediawiki.org/wiki/Download to the /opt/ directory on the server:

cd /opt/
wget https://releases.wikimedia.org/mediawiki/1.27/mediawiki-1.27.1.tar.gz
tar -xvzf mediawiki-1.27.1.tar.gz
mv /opt/mediawiki-1.27.1/ /var/www/html/mediawiki

All files have to be readable by the web server, so set a proper ownership:

chown www-data:www-data -R /var/www/html/mediawiki

Create a new MySQL database and user:

mysql -u root -p
mysql> SET GLOBAL sql_mode='';
mysql> CREATE DATABASE wikidb;
mysql> CREATE USER 'wikiuser'@'localhost' IDENTIFIED BY 'y0uR-pa5sW0rd';
mysql> GRANT ALL PRIVILEGES ON wikidb.* TO 'wikiuser'@'localhost';
mysql> quit

Do not forget to replace ‘y0uR-pa5sW0rd’ with a strong password.

Create a new virtual host directive in Apache. For example, create a new Apache configuration file named ‘mediawiki.conf’ on your virtual server:

touch /etc/apache2/sites-available/mediawiki.conf
ln -s /etc/apache2/sites-available/mediawiki.conf /etc/apache2/sites-enabled/mediawiki.conf
vi /etc/apache2/sites-available/mediawiki.conf

Then, add the following lines:

<VirtualHost *:80>
ServerAdmin admin@your-domain.com
DocumentRoot /var/www/html/mediawiki/
ServerName your-domain.com
ServerAlias www.your-domain.com
<Directory /var/www/html/mediawiki/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
ErrorLog /var/log/apache2/your-domain.com-error_log
CustomLog /var/log/apache2/your-domain.com-access_log common

Remove the 000-default.conf file:

rm /etc/apache2/sites-enabled/000-default.conf

Restart the Apache web server for the changes to take effect:

service apache2 restart

Open http://your-domain.com in your favorite web browser, click on the ‘set up the wiki’ hyperlink and follow the easy instructions on the install screen inserting the necessary information as requested:

Select your language and the Wiki language. On the next page, click ‘continue’ if all requirements are met, then enter the following information:

Database Host: localhost
Database name: wikidb
Database username: wikiuser
Database password: y0uR-pa5sW0rd   // change this password with your actual password

Click ‘Continue’. On the next page select:

Storage engine: InnoDB
Database character set: UTF-8

Click ‘Continue’. Enter the name of Wiki which will appear in the title bar of the web browser and other places, create an administrator account and install the Wiki.

In order to improve the speed and performance of your MediaWiki installation, add the following lines at the end of the LocalSettings.php file :

vi /var/www/html/mediawiki/LocalSettings.php
# Speed improvements
$wgUseGzip = true;
$wgUseFileCache = true;

# Performance settings
$wgDisableCounters = true;
$wgMiserMode = true;

Set a proper ownership of the LocalSettings.php configuration file:

chown www-data:www-data /var/www/html/mediawiki/LocalSettings.php

That is it. MediaWiki has been installed on your server.

Log in to the MediaWiki administration back-end and start creating new content, add user accounts, extensions etc.

Of course, you don’t have to do any of this if you use one of our MediaWiki VPS Hosting services, in which case you can simply ask our expert Linux admins to install MediaWiki for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.


View Comments

    • Please check for ownership and permissions of your MediaWiki installation path.

      You should be able to fix the permission problem using:

      chown www-data:www-data -R /var/www/html/mediawiki

      Replace www-data with your nginx user and /var/www/html/mediawiki with the actual path to your MediaWiki installation.