• Get In Touch
November 2, 2016

How to Install and Configure Mediawiki on Ubuntu-16.04

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Introduction

Mediawiki is a free and open source software package written in PHP, developed by the Wikimedia Foundation. Mediawiki runs on many websites such as Wikipedia, Wiktionary and Wikimedia Commons. Mediawiki also known as a wiki engine is software that allows users to create and edit pages via a web browser.

In this tutorial, we will learn how to install and configure Mediawiki on Ubuntu-16.04 server.

Requirements

  • A server runing Ubuntu-16.04.
  • A non-root user with sudo privileges setup on your server.

Getting Started

Before starting, update your system with the following command:

sudo apt-get update -y
sudo apt-get upgrade -y

Once system is up-to-date, you will need to install LAMP stack on your server.

You can install it with the following command:

sudo apt-get install apache2 mariadb-server php7.0-mysql php-xml php7.0-curl php7.0-json php7.0-cgi php7.0 libapache2-mod-php7.0 imagemagick php7.0-intl php7.0-gd php7.0-mbstring

Output:

    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following additional packages will be installed:
      apache2-bin apache2-data apache2-utils fontconfig fontconfig-config fonts-dejavu-core ghostscript gsfonts hicolor-icon-theme imagemagick-6.q16
      imagemagick-common libaio1 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libcairo2 libcgi-fast-perl libcgi-pm-perl libcroco3
      libcupsfilters1 libcupsimage2 libdatrie1 libdbd-mysql-perl libdbi-perl libdjvulibre-text libdjvulibre21 libencode-locale-perl libfcgi-perl
      libfftw3-double3 libfontconfig1 libgd3 libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-common libgraphite2-3 libgs9 libgs9-common libharfbuzz0b
      libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libijs-0.35 libilmbase12 libio-html-perl
      libjbig0 libjbig2dec0 libjpeg-turbo8 libjpeg8 liblcms2-2 liblqr-1-0 liblua5.1-0 liblwp-mediatypes-perl libmagickcore-6.q16-2
      libmagickcore-6.q16-2-extra libmagickwand-6.q16-2 libnetpbm10 libopenexr22 libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libpaper-utils
      libpaper1 libpixman-1-0 librsvg2-2 librsvg2-common libterm-readkey-perl libthai-data libthai0 libtiff5 libtimedate-perl liburi-perl libvpx3
      libwmf0.2-7 libxcb-render0 libxcb-shm0 libxpm4 libxrender1 libxslt1.1 mariadb-client-10.0 mariadb-client-core-10.0 mariadb-common
      mariadb-server-10.0 mariadb-server-core-10.0 netpbm php-common php7.0-cli php7.0-common php7.0-opcache php7.0-readline php7.0-xml poppler-data
      ssl-cert
    Suggested packages:
      apache2-doc apache2-suexec-pristine | apache2-suexec-custom ghostscript-x hpijs imagemagick-doc autotrace cups-bsd | lpr | lprng enscript ffmpeg
      gimp gnuplot grads graphviz hp2xx html2ps libwmf-bin mplayer povray radiance sane-utils texlive-base-bin transfig ufraw-batch xdg-utils php-pear
      libclone-perl libmldbm-perl libnet-daemon-perl libsql-statement-perl libfftw3-bin libfftw3-dev libgd-tools fonts-droid texlive-lang-cjk
      libdata-dump-perl libipc-sharedcache-perl liblcms2-utils inkscape librsvg2-bin libwww-perl libwmf0.2-7-gtk mariadb-test tinyca poppler-utils
      fonts-japanese-mincho | fonts-ipafont-mincho fonts-japanese-gothic | fonts-ipafont-gothic fonts-arphic-ukai fonts-arphic-uming fonts-nanum
      openssl-blacklist
    The following NEW packages will be installed:
      apache2 apache2-bin apache2-data apache2-utils fontconfig fontconfig-config fonts-dejavu-core ghostscript gsfonts hicolor-icon-theme imagemagick
      imagemagick-6.q16 imagemagick-common libaio1 libapache2-mod-php7.0 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libcairo2
      libcgi-fast-perl libcgi-pm-perl libcroco3 libcupsfilters1 libcupsimage2 libdatrie1 libdbd-mysql-perl libdbi-perl libdjvulibre-text libdjvulibre21
      libencode-locale-perl libfcgi-perl libfftw3-double3 libfontconfig1 libgd3 libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-common libgraphite2-3 libgs9
      libgs9-common libharfbuzz0b libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libijs-0.35
      libilmbase12 libio-html-perl libjbig0 libjbig2dec0 libjpeg-turbo8 libjpeg8 liblcms2-2 liblqr-1-0 liblua5.1-0 liblwp-mediatypes-perl
      libmagickcore-6.q16-2 libmagickcore-6.q16-2-extra libmagickwand-6.q16-2 libnetpbm10 libopenexr22 libpango-1.0-0 libpangocairo-1.0-0
      libpangoft2-1.0-0 libpaper-utils libpaper1 libpixman-1-0 librsvg2-2 librsvg2-common libterm-readkey-perl libthai-data libthai0 libtiff5
      libtimedate-perl liburi-perl libvpx3 libwmf0.2-7 libxcb-render0 libxcb-shm0 libxpm4 libxrender1 libxslt1.1 mariadb-client-10.0
      mariadb-client-core-10.0 mariadb-common mariadb-server mariadb-server-10.0 mariadb-server-core-10.0 netpbm php-common php-xml php7.0 php7.0-cgi
      php7.0-cli php7.0-common php7.0-curl php7.0-gd php7.0-intl php7.0-json php7.0-mbstring php7.0-mysql php7.0-opcache php7.0-readline php7.0-xml
      poppler-data ssl-cert
    0 upgraded, 107 newly installed, 0 to remove and 0 not upgraded.
    Need to get 27.2 MB/43.6 MB of archives.
    After this operation, 250 MB of additional disk space will be used.
    Do you want to continue? [Y/n] Y

    Get:1 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 libapr1 amd64 1.5.2-3 [86.0 kB]
    Get:2 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 libaprutil1 amd64 1.5.4-1build1 [77.1 kB]
    Get:3 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 libaprutil1-dbd-sqlite3 amd64 1.5.4-1build1 [10.6 kB]
    Get:4 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 libaprutil1-ldap amd64 1.5.4-1build1 [8,720 B]
    Get:5 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 liblua5.1-0 amd64 5.1.5-8ubuntu1 [102 kB]
    Get:6 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 apache2-bin amd64 2.4.18-2ubuntu3.1 [923 kB]
    Get:7 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 apache2-utils amd64 2.4.18-2ubuntu3.1 [81.3 kB]                                 
    Get:8 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 apache2-data all 2.4.18-2ubuntu3.1 [162 kB]                                     
    Get:9 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 apache2 amd64 2.4.18-2ubuntu3.1 [86.7 kB]                                       
    Get:10 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 fonts-dejavu-core all 2.35-1 [1,039 kB]                                                
    Get:11 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 fontconfig-config all 2.11.94-0ubuntu1.1 [49.9 kB]                             
    Get:12 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libfontconfig1 amd64 2.11.94-0ubuntu1.1 [131 kB]                               
    Get:13 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 fontconfig amd64 2.11.94-0ubuntu1.1 [178 kB]                                   
    Get:14 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 imagemagick-common all 8:6.8.9.9-7ubuntu5.1 [42.1 kB]                          
    Get:15 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 libfftw3-double3 amd64 3.3.4-2ubuntu1 [718 kB]                                         
    Get:16 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 libjpeg-turbo8 amd64 1.4.2-0ubuntu3 [111 kB]                                           
    Get:17 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 liblcms2-2 amd64 2.6-3ubuntu2 [137 kB]                                                 
    Get:18 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 liblqr-1-0 amd64 0.4.2-2 [23.6 kB]                                                     
    Get:19 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 libjbig0 amd64 2.1-3.1 [26.6 kB]                                                       
    .
    .
    .

Once installation is complete, you will need to enable Apache rewrite module.

You can do this by running the following command:

sudo a2enmod rewrite

Now, restart the Apache service for the changes to take effect:

sudo systemctl restart apache2

Installing Mediawiki

Before starting, you will need to download the latest version of Mediawiki from https://www.mediawiki.org/wiki/Download.

You can download Mediawiki using wget command as follows:

cd /opt/
sudo wget https://releases.wikimedia.org/mediawiki/1.27/mediawiki-1.27.1.tar.gz
sudo tar -xvzf mediawiki-1.27.1.tar.gz

Next, move mediawiki-1.27.1 to Apache document root directory:

sudo mv /opt/mediawiki-1.27.1 /var/www/html/mediawiki

Change the ownership of mediawiki directory to www-data:

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

Configuring the Database

Default Mariadb installation is not secure, so you will need to secure it first. You can secure it using mysql_secure_installation script:

sudo mysql_secure_installation

Answer all the questions as follows:

    NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
          SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

    In order to log into MariaDB to secure it, we'll need the current
    password for the root user.  If you've just installed MariaDB, and
    you haven't set the root password yet, the password will be blank,
    so you should just press enter here.

    Enter current password for root (enter for none):
    OK, successfully used password, moving on...

    Setting the root password ensures that nobody can log into the MariaDB
    root user without the proper authorisation.

    You already have a root password set, so you can safely answer 'n'.

    Change the root password? [Y/n] n
     ... skipping.

    By default, a MariaDB installation has an anonymous user, allowing anyone
    to log into MariaDB without having to have a user account created for
    them.  This is intended only for testing, and to make the installation
    go a bit smoother.  You should remove them before moving into a
    production environment.

    Remove anonymous users? [Y/n] Y

    Normally, root should only be allowed to connect from 'localhost'.  This
    ensures that someone cannot guess at the root password from the network.

    Disallow root login remotely? [Y/n] Y
     ... Success!

    By default, MariaDB comes with a database named 'test' that anyone can
    access.  This is also intended only for testing, and should be removed
    before moving into a production environment.

    Remove test database and access to it? [Y/n] Y
     - Dropping test database...
     ... Success!
     - Removing privileges on test database...
     ... Success!

    Reloading the privilege tables will ensure that all changes made so far
    will take effect immediately.

    Reload privilege tables now? [Y/n] Y
     ... Success!

    Cleaning up...

    All done!  If you've completed all of the above steps, your MariaDB
    installation should now be secure.

    Thanks for using MariaDB!

Next, you will need to login MariaDB console and create a Database for the Mediawiki.
You can do this by running the following command:

mysql -u root -p

Enter the password for root user, you should see the following output:

    Welcome to the MariaDB monitor.  Commands end with ; or g.
    Your MariaDB connection id is 106
    Server version: 10.0.27-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04

    Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

    MariaDB [(none)]> 

Once you are logged in to MariaDB console, create a database and user with the following command:

MariaDB [(none)]> CREATE DATABASE mediawikidb;

    Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';

    Query OK, 0 rows affected (0.06 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON wikidb.* TO 'user'@'localhost';

    Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> exit

Configure Apache for Mediawiki

Once database is configured, you will need to configure Apache for Mediawiki.
So, you will need to create new virtual host file for Mediawiki:

sudo nano /etc/apache2/sites-available/mediawiki.conf

Add the following lines:


ServerAdmin admin@yourdomain.com DocumentRoot /var/www/html/mediawiki/ ServerName 192.168.15.189 Options FollowSymLinks AllowOverride All Order allow,deny allow from all ErrorLog /var/log/apache2/mediawiki-error_log CustomLog /var/log/apache2/mediawiki-access_log common

Save and close the file when you are finished.

Next, you will need to enable mediawiki site and disable 000-default site.

You can do this by running the following command:

sudo a2ensite mediawiki
sudo a2dissite 000-default

Next, reload apache service with the following command:

systemctl restart apache2

Accessing Mediawiki

Once everything is setup properly, it’s time to access Mediawiki.

Open your favourite web browser and type the URL http://your-server-ip, and hit Enter button, you should see the following page:

HP_NO_IMG/data/uploads/users/7ecb43a5-b365-4ebf-93d5-f3b632f29f33/546322523.png” alt=”” />

Next, click on the set up the wiki hyperlink and follow the instructions on the screen and fill up the necessary information as required.

Select your language and the Wiki language. On the next page, click continue , then enter the following information:

    Database Host: localhost
    Database name: mediawikidb
    Database username: user
    Database password: password

Next, click on the Continue, and select:

    Storage engine: InnoDB
    Database character set: UTF-8

Next, click on Continue and 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.

The configuration process will prompt you to download a LocalSettings.php, so download it and save it to /var/www/html/mediawiki directory.

Also, if you want to improve the speed and performance of your MediaWiki installation, add the following lines at the end of the LocalSettings.php file :

sudo /var/www/html/mediawiki/LocalSettings.php

Add the following lines:

    # Speed improvements
    $wgUseGzip = true;
    $wgUseFileCache = true;

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

Once you are finished, open your web browser and type the URL http://your-server-ip to see your new wiki:

HP_NO_IMG/data/uploads/users/7ecb43a5-b365-4ebf-93d5-f3b632f29f33/610959999.png” alt=”” />

Conclusion

Congratulations! You have successfully installed MediaWiki on your Ubuntu-16.04 server. You can now easily create your own wiki page using Mediawiki.

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Share this Article!

Related Posts

Node.js Authentication – A Complete Guide with Passport and JWT

Node.js Authentication – A Complete Guide with Passport and JWT

Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will be avoided or at least […]

Node.js and MongoDB: How to Connect MongoDB With Node

Node.js and MongoDB: How to Connect MongoDB With Node

MongoDB is a document-oriented NoSQL database, which was born in 2007 in California as a service to be used within a larger project, but which soon became an independent and open-source product. It stores documents in JSON, a format based on JavaScript and simpler than XML, but still with good expressiveness. It is the dominant […]

Using MySQL with Node.js: A Complete Tutorial

Using MySQL with Node.js: A Complete Tutorial

Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you need to scale an application, […]

Node.Js Vs Django: Which Is the Best for Your Project

Node.Js Vs Django: Which Is the Best for Your Project

Django and NodeJs are two powerful technologies for web development, both have great functionality, versatile applications, and a great user interface. Both are open source and can be used for free. But which one fits your project best? NodeJs is based on JavaScript, while Django is written in Python. These are two equally popular technologies […]

Nodejs Vs PHP:  Which Works Best?

Nodejs Vs PHP: Which Works Best?

Before getting into the “battle” between Node.js and PHP we need to understand why the issue is still ongoing. It all started with the increased demand for smartphone applications, their success forcing developers to adapt to new back-end technologies that could handle a multitude of simultaneous requests. JavaScript has always been identified as a client-side […]