Deploying MediaWiki + MySQL Using Docker

Uttakarsh Tikku
4 min readMar 16, 2020

--

If you’re here, you have probably decided to create your own wiki server to manage your knowledge base. That’s amazing!

So let’s learn about the basics first: what is MediaWiki? and why do you need to have your own knowledge base?

What is MediaWiki?

Well it’s a server-based application which allows you to create a knowledge base, with documents, images and multimedia. It’s extremely powerful and extremely scalable and can be run over server farms, thus allowing you to manage high volumes of traffic.

Why do I need to have my own knowledge base?

Well simply put, a knowledge base is just a repository of data. It can be an internal repository or an external repository. So let’s learn about both, shall we.

External repositories are meant for documenting stuff that you need to show the outside world, the tip of the iceberg, the stuff that the users of your product need to be worried about.

An internal repository, however consists of information that may be useful inside a company, like the Onboarding kits, development best practices documentation, code documentation, etc. The list is quite long.

The knowledge bases can also be used for personal projects, as yours truly has used many times. I used it to document the findings of my research and instantly fell in love with the tool.

So no matter who you are, a researcher, a hobbyist, a software developer… you need a knowledge base. MediaWiki just happens to be one of the best, open-source and free solution to all your troubles!

So now that we have understood the need for a knowledge base, let’s get on to setting up one.

Here’s what you need:

  1. Docker
  2. A good internet connection
  3. A few minutes

Now that you have all these ready, you will need to create a docker-compose file.

Here’s what a docker-compose.yml file would look like:

version: '3'services:  mediawiki: {...}  database: {...}networks: {...}

Now, MediaWiki can be configured using a host of different databases, like postgres, MySQL, etc etc but it so happens that I love MySQL…. Don’t know why but just do….

So that’s what I’m gonna use.

First things first, let’s see how the mediawiki service is configured:

version: '3'services:mediawiki:
image: mediawiki
restart: always ports: - 8080:80
links:
- database
volumes: - /var/www/html/ database: {...}networks: {...}

So far so good, we are using a mediawiki image, which runs the service on port 80 of the container. The port 80 of the container is mapped to port 8080 on the host system.

Volumes can be interesting. You can either map a folder of your choice to the folder in mediawiki container or just let docker map it to it’s temporary data folder. The above snippet represents a volume managed by docker.

Now, let’s add the database service:

version: '3'services:mediawiki: {...}database:
image: mysql:5.7
restart: always environment: MYSQL_DATABASE: wiki_db MYSQL_ROOT_PASSWORD: root MYSQL_USER: wikimedia MYSQL_PASSWORD: wikimedia volumes: - /var/lib/mysqlnetworks: {...}

Easy-peasy, lemon squeezy!

Here, we are using a mysql version 5.7 database.

Now to connect the two services to each other, let’s create a docker virtual network. The complete docker-compose.yml looks like this:

# MediaWiki with MySQL# Access via "http://localhost:8080"#   (or "http://$(docker-machine ip):8080" if using docker-machine)version: '3'services:  mediawiki:    image: mediawiki    restart: always    networks:      - docker_network    ports:      - 8080:80    volumes:      - /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:    image: mysql:5.7    restart: always    networks:      - docker_network    environment:      MYSQL_DATABASE: wiki_db      MYSQL_ROOT_PASSWORD: root      MYSQL_USER: wikimedia      MYSQL_PASSWORD: wikimedia    volumes:      - /var/lib/mysqlnetworks:  docker_network:    driver: bridge

And voila! Just like that, you have your mediawiki server running. You need to configure the mediawiki service to use the mysql database created in this docker file. To do so, follow these steps:

1. You will be greeted by this page:

2. Select the correct database like so:

3. Enter the connection details of the database:

4. Enter the details of your wiki:

Most of this setup is really simple and straightforward… so let’s skip to the end:

5. Download the LocalSettings.php:

And now, just copy the downloaded LocalSettings.php to /var/www/html/ inside the mediawiki docker container using the command given below:

docker cp c:\path\to\downloaded\file container_name:/var/www/html/

So there you have it! Your very own MediaWiki server, using MySQL database and Docker containers!

--

--

Uttakarsh Tikku

I am a Machine Learning developer with interests in NLP, MLOps, Scalable Machine Learning and FinTech