RPI Computers

Personal Mediawiki with Raspberry PI and Docker

In this tutorial, I’m going to show you how to install Mediawilki on a Raspberry PI computer.

Sharing knowledge is was the very first scope of internet at its born. The greatest expression of this is still Wikipedia, letting people share what they know with all the world. But you can get your knowledge portal identical to Wikipedia with the open source Mediawiki on Raspberry PI.

What Is MediaWiki

MediaWiki is an open source collaboration and documentation platform used to share knowledge between people across Internet. It is the base of the famous Wikipedia website.

Licensed under GNU General Public License (GPL), it is extremely powerful, scalable and feature-rich. MediaWiki uses PHP for its front-end to display information to your browser and a number of databases variety (most common being MySQL).

In this article, I’m going to show you how to create your personal wiki with the cheap and powerful Raspberry PI. To simplify installation and setup, I’ll use Docker and docker-compose to deploy services with a single command line and a few configuration files. Instead of MySQL, our database will be built on custom MariaDB installation (fork of MySQL), which is performing better on Raspberry PI boards.

I will use a Raspberry Pi 3 model A+, but this guide will work also with newer Raspberry PI boards. You can check hardware differences with Raspberry PI comparison between latest models.

What We need

As usual, I suggest adding from now to your favourite e-commerce shopping cart all the needed hardware, so that at the end you will be able to evaluate overall costs and decide if to continue with the project or remove them from the shopping cart. So, hardware will be only:

Check hardware prices with the following links:

Step-by-Step Procedure

Environment Preparation

Start with a fresh Raspberry PI OS Lite installation. Then make sure your operating system is updated and upgraded:

sudo apt update
sudo apt upgrade

Our environment will be completed installing Docker and docker-compose (using linked procedure).

Installing Database and MediaWiki

Using docker will result in a huge simplification for the installation procedure. Create a directory that will include our configuration files. Consider that by default, docker-compose will prepend to containers your directory name, even if you can easily edit it later. From terminal:

mkdir mediawiki
cd mediawiki

The following files will be created in this directory:

docker-compose.yml
Dockerfile
mySqlScript.sql

Docker-compose yaml file

Create a docker compose file:

nano docker-compose.yml

and add the following code;

# My MediaWiki
# from peppe8o.com
version: '3'
services:
 mediawiki:
  image: mediawiki
  restart: unless-stopped
  ports:
   - 8080:80
  links:
   - database
  volumes:
   - mediawiki-www:/var/www/html
 #After initial setup, download LocalSettings.php to the same directory as
 #this yaml and uncomment the following line and use compose to restart
 #the mediawiki service
 # - ./LocalSettings.php:/var/www/html/LocalSettings.php
 database:
  build: .
  restart: unless-stopped
  volumes:
   - mediawiki-db:/var/lib/mysql
volumes:
 mediawiki-www:
 mediawiki-db:

Dockerfile

As you can see, our database will be built on custom installation (please refer to create custom MariaDB container on Raspberry PI for more info).

Create a Dockerfile:

nano Dockerfile

And use the following content inside it:

FROM debian
RUN apt update -y && apt install mariadb-server -y
RUN sed -i 's/bind-address/bind-address = 0.0.0.0 #/i' /etc/mysql/mariadb.conf.d/50-server.cnf
RUN mkdir /mysql_scripts
COPY mySqlScript.sql /mysql_scripts/
RUN /etc/init.d/mariadb start && mysql -uroot --password="" -e "source /mysql_scripts/mySqlScript.sql"
CMD /etc/init.d/mariadb start && tail -f /dev/null

MySQL initialization script

Finally, create your database initialization script:

nano mySqlScript.sql

Use the following code, changing “mediauser” and “mediapassword” with your preferred credentials:

CREATE USER mediauser@'%' IDENTIFIED BY 'mediapassword';
CREATE DATABASE my_wiki;
GRANT ALL PRIVILEGES ON my_wiki.* TO mediauser@'%';
flush privileges;
quit

Service Creation and Initialization

With previous files ready to be used, you will be able to install and have it up only with following command:

docker-compose up -d

This process will require a while to download the required images and install / configure MariaDB.

Once your Raspberry PI prompts you for installation finished, you can go to your favourite browser to configure your MediaWiki installation. Browse url http://<<yourRaspberryIpAddress>>:8080 (in my case, My local Raspberry PI IP address il 192.168.1.177):

First page notifies you that the settings file has not been found. The following steps will create it. Click on “set up the wiki” link. The next page will ask you for your preferred language;

Choose it and click Continue. Next page will warn you that some environmental checks will be performed:

Scrolling down, you should see a green row reporting: “The environment has been checked. You can install MediaWiki.”. Scroll to the bottom and click “Continue”. The next page will require database configuration:

Scroll down to white fields. Leave MariaDB in database type and use the following for other fields (changing mediauser and mediapassword with your ones configured in MySQL initialization script). Note that you have to change Database Host from default “localhost” to “database:3306”:

Scroll down and click continue. The next screen will make you able to use the same user/password configured for database connection also for web access:

You can change and make your configuration more secure (but you need to define a new database user) or keep default and click continue. The next page will ask you the name of your mediawiki page and administration account.

Use your favourite ones (remember to use a strong password). To complete installation, scroll down and select “I’m bored already, just install the wiki.” option, then click Continue. Finally, a confirmation for installation completion will be asked to you:

Click Continue to complete. The next screen will confirm that installation is complete:

Click continue. On the next page, a popup will open giving you a download for a file named “LocalSettings.php”:

Download it locally and copy it to your MediaWiki folder (docker-compose folder) in your Raspberry PI. From the terminal, shut down MediaWiki service:

 docker-compose down

Edit docker-compose.yml file by uncommenting the following line:

  - ./LocalSettings.php:/var/www/html/LocalSettings.php

This will allow the MediaWiki container to import LocalSettings.php file in Apache directory. Finally, our new folder will contain the following files:

docker-compose.yml
Dockerfile
LocalSettings.php
mySqlScript.sql

Start again with docker-compose;

docker-compose up -d

And go back to your browser, refreshing http://<<yourRaspberryIpAddress>>:8080 page. You will find now your Mediawiki page ready:

Final Operations

Once finished, a good security practice is entering your database container and changing the DB root password.

What’s Next

If you want to discover many other projects for your Raspberry PI, you can take a look at peppe8o Raspberry PI tutorials.

Enjoy!

peppe8o

Open source and Raspberry PI lover

View Comments

  • NICE!
    I had to make 1 adjustment:
    Thanks for the really easy to follow tutorial
    ~remke

    COMPOSE_HTTP_TIMEOUT=200 sudo docker-compose up -d

    because of an error:
    ERROR: for mediawiki_mediawiki_1 UnixHTTPConnectionPool(host='localhost', port=None): Read timed out. (read timeout=60)

    -> COMPOSE_HTTP_TIMEOUT=200 sudo docker-compose up -d
    ERROR: No such container: c4678ed7f14288eb301415a28283d63e45f5e92a3e36af20dcf1cda491cb04c2
    -> FIX:
    sudo docker stop c4678ed7f14288eb301415a28283d63e45f5e92a3e36af20dcf1cda491cb04c2
    c4678ed7f14288eb301415a28283d63e45f5e92a3e36af20dcf1cda491cb04c2
    pi@raspberrypi:~/mediawiki $ sudo docker rm -f c4678ed7f14288eb301415a28283d63e45f5e92a3e36af20dcf1cda491cb04c2
    c4678ed7f14288eb301415a28283d63e45f5e92a3e36af20dcf1cda491cb04c2
    pi@raspberrypi:~/mediawiki $ sudo docker-compose up -d
    mediawiki_database_1 is up-to-date

  • Final adjustment.
    The downoaded LocalSettings.php:
    - not only remove the hash but also make sure to line out the "-" at the same location as the other earlier line ;)
    volumes:
    - mediawiki-www:/var/www/html
    - ./LocalSettings.php:/var/www/html/LocalSettings.php
    Otherwise the last - will be not at the right position (Yml)

    ~remke

  • Very nice project. Unfortunately after an update, it suddenly stopped working and refuses any connection... Any suggestions?

  • I tried building this project from scratch, but it crashes at the very last step of the Dockerfile...

    Building database
    Step 1/7 : FROM debian
    ---> e9cf93b473f4
    Step 2/7 : RUN apt update && apt install mariadb-server -y
    ---> Using cache
    ---> e59f6858c661
    Step 3/7 : RUN sed -i 's/bind-address/bind-address = 0.0.0.0 #/i' /etc/mysql/mariadb.conf.d/50-server.cnf
    ---> Using cache
    ---> 1a3e72c65d80
    Step 4/7 : RUN mkdir /mysql_scripts
    ---> Using cache
    ---> 8504f050de47
    Step 5/7 : COPY mySqlScript.sql /mysql_scripts/
    ---> Using cache
    ---> 5d464d21127e
    Step 6/7 : RUN /etc/init.d/mysql start && mysql -u root --password="" -e "source /mysql_scripts/mySqlScript.sql"
    ---> Running in 251dda90a496
    /bin/sh: 1: /etc/init.d/mysql: not found
    ERROR: Service 'database' failed to build: The command '/bin/sh -c /etc/init.d/mysql start && mysql -u root --password="" -e "source /mysql_scripts/mySqlScript.sql"' returned a non-zero code: 127

      • The instructions are very clear and got almost to the end. I too ran into the same error as Ralf experienced.
        Below is screen capture:
        Building database
        Step 1/7 : FROM debian
        ---> f8dd32c4c981
        Step 2/7 : RUN apt update && apt install mariadb-server -y
        ---> Using cache
        ---> 45ee198599ba
        Step 3/7 : RUN sed -i 's/bind-address/bind-address = 0.0.0.0 #/i' /etc/mysql/mariadb.conf.d/50-server.cnf
        ---> Using cache
        ---> 633b054a856f
        Step 4/7 : RUN mkdir /mysql_scripts
        ---> Using cache
        ---> e08b5b733efa
        Step 5/7 : COPY mySqlScript.sql /mysql_scripts/
        ---> Using cache
        ---> 9569bb081dcd
        Step 6/7 : RUN /etc/init.d/mysql start && mysql -uroot --password="" -e "source /mysql_scripts/mySqlScript.sql"
        ---> Running in 6562827a2280
        /bin/sh: 1: /etc/init.d/mysql: not found
        ERROR: Service 'database' failed to build: The command '/bin/sh -c /etc/init.d/mysql start && mysql -uroot --password="" -e "source /mysql_scripts/mySqlScript.sql"' returned a non-zero code: 127

        Appreciate your help in advance.

        • Hi Guru,
          Please double check my tutorial on MariaDB dockerfile. The last rows are recently changed to:

          RUN /etc/init.d/mariadb start && mysql -uroot --password="" -e "source /mysql_scripts/mySqlScript.sql"
          CMD /etc/init.d/mariadb start && tail -f /dev/null

          This should solve the issue. I'm going to update this page too

  • Finally a docker tutorial for Mediawiki that actually works!!! I've tried several others and they all bombed at some point. I'm new to all this stuff, so I don't have the skills to troubleshoot and fix what the issue is. This worked perfectly other than when I uncommented the line for the LocalSettings.php file it crashed until I figured out I had to make the dash at the beginning line up with the one in the active line above it. Thank you very much!

    Oh, and I'm not even doing this on a Pi but in a VPS but it worked just fine.

  • Tried today to use the manual. Unfortunately my pi says „unknown command“ when I try to run the command „docker-compose up -d“. But its up to date.

    • Hi, thank you for your feedback.
      From the linked tutorial you probably missed the part about installing docker compose. In any case, the new docker versions already include the compose option (without the dash character), so you should be able to use the following command:
      docker compose up -d
      Please let me know if this works

Published by
peppe8o

Recent Posts

Some links in this post may be affiliate links. We may get paid if you buy something or take an action after clicking one of these, but without addictional costs for you compared to direct buying.

SPI communication between two Arduinos

In this tutorial, we will use two Arduino Uno to demonstrate the Serial Peripheral Interface…

2 weeks ago

Automatic irrigation system with Arduino and Sensors

In this tutorial, we will be making an automatic irrigation system (AIS) with Arduino and…

3 weeks ago

Beginner’s Guide to Use Python Virtual Environment with Raspberry PI (venv)

This tutorial will show you how to use Python Virtual Environment with Raspberry PI computer…

4 weeks ago

Get Betting Odds with Raspberry PI and Odds-API (free)

This tutorial will show you how to get betting odds with Raspberry PI by using…

1 month ago

Backup Raspberry PI (computer) Data with Rsync to Remote NAS

This tutorial will show you how to perform the backup of Raspberry PI (computer board)…

1 month ago

Honeygain and Raspberry PI: Earn by Sharing Internet Connection

This tutorial will show you how to install Honeygain on a Raspberry PI computer board…

1 month ago