How to Install MediaWiki on Ubuntu 16.04/17.04 with Apache or Nginx

This tutorial is going to show you how to install MediaWiki on Ubuntu 16.04/17.04. MediaWiki is the backend software that powers Wikipedia. It’s free open-source and the most widely used wiki software today. Well-known users of MediaWiki includes Wikipedia.org, wikia.com.

You can use MediaWiki to create your own private or public wiki. MediaWiki has a lot of useful extensions that have been created both for Wikipedia and for other wiki sites.

Prerequisites

MediaWiki is a program written in PHP. To follow this tutorial, first you need to have a LAMP or LEMP stack installed on your Ubuntu 16.04/17.04 server. If you haven’t already done so, then please check out one of the following tutorial:

After installing LAMP or LEMP, read the following instructions to install MediaWiki.

Step 1: Downloading MediaWiki

You can use two ways to download MediaWiki: downloading the tarball or cloning the repository via Git. Using Git is the recommended method, because it’s easy to install and you can update MediaWiki much more easily later on.

Install Git and clone the latest version of MediaWiki to your system.

sudo apt install git

git clone https://gerrit.wikimedia.org/r/p/mediawiki/core.git

A directory named core will be created, you can rename it to mediawiki.

mv core mediawiki

Then we move this directory to /var/www/.

sudo mv mediawiki /var/www/

Next, we need to install external dependencies via Composer.

sudo apt install composer

cd /var/www/mediawiki/

composer install --no-dev

Once all dependencies are installed, run the following command to set web server user (www-data) as the owner of this directory.

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

Step 2: Creating a Database

Log into MariaDB server with the command below. You will need to enter the MariaDB root password.

mysql -u root -p

Create a database for MediaWiki. This tutorial name the database wikidb, but you can use whatever name you like.

CREATE DATABASE wikidb;

Then run the following command at MariaDB prompt to create a database user and grant privileges to this user. Replace wikidb, wikiuser and password with your preferred database name, database username and user password respectively.

GRANT ALL PRIVILEGES ON wikidb.* TO 'wikiuser'@'localhost' IDENTIFIED BY 'password';

Next, flush MariaDB privileges and exit.

flush privileges;

exit;

Step 3: Setting up Apache Virtual Host

In this step, we will create an Apache virtual host for MediaWiki. If you use Nginx, then skip to the Nginx section below.

Create a virtual host file for MediaWiki.

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

Copy and paste the following text into the file. Replace wiki.your-domain.com with your actual domain name. Don’t forget to create A record for this domain name.

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www//mediawiki/
    ServerName wiki.your-domain.com

    <Directory /var/www/html/mediawiki/>
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ErrorLog /var/log/apache2/your-domain.com-error_log
    CustomLog /var/log/apache2/your-domain.com-access_log common
</VirtualHost>

Save and close the file. Then enable this virtual host.

sudo a2ensite mediawiki.conf

Reload Apache for the above changes to take effect.

sudo systemctl reload apache2

Setting up Nginx Server Block

Create a server block file for MediaWiki under /etc/nginx/conf.d/ directory.

sudo nano /etc/nginx/conf.d/mediawiki.conf

Copy the following text and paste it into the file. Replace wiki.your-domain.com with your actual domain name. Don’t forget to create A record for this domain name.

server {
        listen 80;
        server_name wiki.your-domain.com;

        root /var/www/mediawiki;
        index index.php;

        location / {
                try_files $uri $uri/ /index.php;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.ht {
          deny all;
         }

        location ~ \.php$ {
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
            include snippets/fastcgi-php.conf;
        }
}

Save and close the file. Then test Nginx configuration.

sudo nginx -t

If the test is successful, reload Nginx web server.

sudo systemctl reload nginx

Step 4: Running the Web-based Installation Script

Go to wiki.you-domain.com in your web browser to start the web-based installation script. Click set up the wiki link to start the setup wizard.

how to install mediawiki

Next, select a language to use for the MediaWiki installation and for the wiki itself.

install mediawiki on ubuntu 16.04

The setup wizard will then check your server’s environment, such as PHP extensions.

mediawiki ubuntu

You can install required packages with the following command.

sudo apt install php-mbstring php-json php-mysql php-curl php-intl php-gd texlive

If you use Apache with PHP module, then you need to restart Apache for the changes to take effect.

sudo systemctl restart apache2

Refresh the MediaWiki setup webpage and go to the next step. You will have to configure the database settings. Select MySQL for “Database type”. Enter localhost for Database host and enter the name of the database you created earlier, as well as the database username and password.

ubuntu mediawiki

In the next step, you can choose the database storage engine and character set. It’s recommended to choose the default settings.

mediawiki database

Then enter the name of your Wiki and create an admin account.

ubuntu 16.04 mediawiki

In the Options page, you have the option to set up your wiki as Open wiki, account creation required, authorized editors only and a private wiki. Then you can choose a license.

mediawiki ubuntu 16.04

Click Continue to begin the installation of Mediawiki.

private wiki

A LocalSettings.php file will be generated in the installation process. You need to download this file and put it in /var/www/mediawiki/ directory of your Ubuntu 16.04/17.04 server. Once that’s done, you will be able to access your newly-installed MediaWiki at http://wiki.your-domain.com.

Downloading and Enabling the Vector Skin

To install the default Skin named Vector, run the following command in /var/www/mediawiki/skins/ directory.

cd /var/www/mediawiki/skins/

sudo git clone https://gerrit.wikimedia.org/r/mediawiki/skins/Vector

To enable this skin, edit LocalSettings.php file.

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

Copy the following line and paste it at the end of the file.

wfLoadSkin( 'Vector' );

Save and close the file. Then refresh the home page of your wiki.

mediawiki vector skin

To create a page for a term, simply go to

wiki.your-domain.com/index.php/your-term

or

wiki.your-domain.com/index.php?title=your-term

This tutorial described how to install MediaWiki on Ubuntu 16.04/17.04. I hope this helped you.

Rate this tutorial
[Total: 18 Average: 4]

4 Responses to “How to Install MediaWiki on Ubuntu 16.04/17.04 with Apache or Nginx

  • vanhussen
    5 years ago

    Friend,

    “Downloading and Enabling the Vector Skin”

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

    No need again for MediaWiki 1.33.1

  • russelld
    5 years ago

    Hi,
    after

    sudo apt install composer

    need to add user to group www-data

    sudo usermod -a -G www-data `whoami` 

    then this will run:

    cd /var/www/mediawiki/
                        composer install --no-dev
  • yogi_winardhana
    4 years ago

    Hello,

    I can’t continue through the installation

    I got this error
    Your session data was lost! Check your php.ini and make sure session.save_path is set to an appropriate directory.

    Any help ?

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here