Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Deploy Your Own MediaWiki Wiki

Wki

Steps

Copy the following contents into a docker-compose.yml file

version: '3'
services:
  mediawiki:
    container_name: wiki
    image: mediawiki
    restart: always
    ports:
      - 80:80
    links:
      - database
    volumes:
      - $HOME/volumes/mediawiki/images:/var/www/html/images
      # 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
      # - $HOME/volumes/mediawiki/LocalSettings.php:/var/www/html/LocalSettings.php

  database:
    image: mariadb
    container_name: db
    restart: always
    ports:
        - 3306:3306
    environment:
      # @see https://phabricator.wikimedia.org/source/mediawiki/browse/master/includes/DefaultSettings.php
      MYSQL_RANDOM_ROOT_PASSWORD: 1
      MYSQL_DATABASE: my_wiki
      MYSQL_USER: wikiuser
      MYSQL_PASSWORD: example
    volumes:
       - $HOME/volumes/mysql/data:/var/lib/mysql

Change the MYSQL_PASSWORD to something random by executing:

SEARCH="MYSQL_PASSWORD: example"
REPLACE="MYSQL_PASSWORD: `openssl rand -base64 32`"
FILEPATH="docker-compose.yml"
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH

Start the containers with:

docker-compose up

Navigate to your wiki server's IP address or hostname and complete the installation guide by clicking on the link.

Database Connection Details

The hardest part of the guide is filling in the database connection details. For the host you need to specify:

db://localhost

The database user is wikiuser.

You will need to get the password from your docker-compose.yml file as we set it to something random using a script above.

LocalSettings File

When you finish, you will automatically download a LocalSettings.php file. Copy the contents of this file. Then open up the editor to where the file needs to be and paste it:

sudo vim $HOME/volumes/mediawiki/LocalSettings.php
sudo chmod 755 $HOME/volumes/mediawiki/LocalSettings.php

Then uncomment the LocalSettings.php volume line in the docker-compose.yml file.

version: '3'
services:
  mediawiki:
    container_name: wiki
    image: mediawiki
    restart: always
    ports:
      - 80:80
    links:
      - database
    volumes:
      - $HOME/volumes/mediawiki/images:/var/www/html/images
      # 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
      - $HOME/volumes/mediawiki/LocalSettings.php:/var/www/html/LocalSettings.php

  database:
    image: mariadb
    container_name: db
    restart: always
    ports:
        - 3306:3306
    environment:
      # @see https://phabricator.wikimedia.org/source/mediawiki/browse/master/includes/DefaultSettings.php
      MYSQL_RANDOM_ROOT_PASSWORD: 1
      MYSQL_DATABASE: my_wiki
      MYSQL_USER: wikiuser
      MYSQL_PASSWORD: example
    volumes:
       - $HOME/volumes/mysql/data:/var/lib/mysql

Restart The Containers

Now stop and start your containers with:

docker-compose down
docker-compose up

Check Out Your Wiki

Now navigate to your wiki's IP or hostname in your browser and you should see:

Click the login link to get to the login page:

Once you have logged in using the username and password you filled in during the installation guide, you should see: