MediaWiki Docker[part one]

For a side project of mine, I was looking for a tool to collect a lot of information. The focus was at first to have a hackmd instance or something like it. My friend, who wants to use it with me, wanted to have access control over some of the content. After researching it, I saw that none of the intended tools provides such a thing. Instead, my friend suggested MediaWiki. While I refused at first, I’ve decided to take a look at it first. The last time was something around 2010 or so. I have to admit that a lot has changed.

So I conitnued on the tts type of services and started to look for a docker container. MediaWiki provides this, but only with support for MySQL, which I disliked. A look into the container showed, that it is not much necessary to get a postgres db running here.

In this post I’m going to document the installation and configuration steps. I guess it will take some posts to get everything covered. However, it is also a work in process.

Installation of Media Wiki with a postgres database backend

At first I re-used the same database container from postgres with the default image from alpine. MediaWiki provides some images, similar to the postgres I use the alpine image. I copied the docker-compose file from my ttrss post as template with some changes. Creating the local volumes and update the volume path and setting the password:

version: '3'
    image: mediawiki
    restart: always
      - 8080:80
      - db
    #  - /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
      # - ./LocalSettings.php:/var/www/html/LocalSettings.php
    restart: always
    image: 'postgres:13-alpine'
      - "./volumes/postgresql:/var/lib/postgresql/data"
      - POSTGRES_PASSWORD=postgres

Now were everything is in place I run the first docker-compose up. Without much issue the media wiki container startes, also is the postgres db, neat. Access via Port 8080 seems fine and so does the MediaWiki Setup until I have to select the databse. Here comes the first expected issue: We can’t select postgres. Why?

PHP in MediaWiki container

The first thought that comes to mind is the fact that PHP is missing the necessary module for it. So let find where PHP has it modules placed. For this we start to work with the running container by starting a shell within the MediaWiki Container.

$ docker-compose exec mediawiki bash

The first oddness in the MediaWiki container is that the PHP is not installation via apt/dpkg. So where is it?

After some whereis and find I figureed out that php is deployed into /usr/local/bin/php by a costom docker-php-* toolkit. I’m checking this with within the docker image project of media wiki. There using a template file for it. That makes it a bit odd at first.

There are using a docker-php-ext-configure and docker-php-ext-enable tool. Once we know how to get it running the Steps are to install and enable the necessary for PHP to make use of postgres. The typical package name is pgsql. Let’s give it a try:

root@6232d8ee302c:/var/www/html# docker-php-ext-install pgsql
Configuring for:
PHP Api Version:         20180731
Zend Module Api No:      20180731
Zend Extension Api No:   320180731
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for PHP prefix... /usr/local
checking for PHP includes... -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/lib/php/extensions/no-debug-non-zts-20180731
checking for PHP installed headers prefix... /usr/local/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... re2c
checking for re2c version... 1.1.1 (ok)
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking for PostgreSQL support... yes, shared
checking for pg_config... not found
configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path

This PHP module requires a system-wide package, which one? Let’s google it. After some google I was please to see that the libpq-dev packages is necessary within the container. So just install it within the container.

There are using a docker-php-ext-configure and docker-php-ext-enable tool. Once we know how to get it running the Steps are to install and enable the necessary for PHP to make use of postgres. The typical package name is pgsql. Let’s give it a try:

root@6232d8ee302c:/var/www/html# apt update                                                                                                 [8/539]
Get:1 buster InRelease [121 kB]
Get:2 buster/updates InRelease [65.4 kB]
Get:3 buster-updates InRelease [51.9 kB]
Get:4 buster/updates/main amd64 Packages [234 kB]
Get:5 buster/main amd64 Packages [7906 kB]
Get:6 buster-updates/main amd64 Packages [7868 B]
Fetched 8387 kB in 2s (3503 kB/s)                         
Reading package lists... Done    
Building dependency tree       
Reading state information... Done
2 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@6232d8ee302c:/var/www/html# apt search libpq-dev
Sorting... Done
Full Text Search... Done
libghc-postgresql-libpq-dev/stable amd64
  low-level binding to libpq

libpq-dev/stable 11.9-0+deb10u1 amd64
  header files for libpq5 (PostgreSQL library)

root@6232d8ee302c:/var/www/html# apt install libpq-dev                    
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
Suggested packages:
The following NEW packages will be installed:
  libpq-dev libpq5
0 upgraded, 2 newly installed, 0 to remove and 2 not upgraded.
Need to get 330 kB of archives.
After this operation, 1460 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 buster/main amd64 libpq5 amd64 11.9-0+deb10u1 [167 kB]
Get:2 buster/main amd64 libpq-dev amd64 11.9-0+deb10u1 [163 kB]
Fetched 330 kB in 0s (1629 kB/s) 
debconf: delaying package configuration, since apt-utils is not installed 
Selecting previously unselected package libpq5:amd64.
(Reading database ... 24883 files and directories currently installed.)
Preparing to unpack .../libpq5_11.9-0+deb10u1_amd64.deb ...
Unpacking libpq5:amd64 (11.9-0+deb10u1) ...
Selecting previously unselected package libpq-dev.
Preparing to unpack .../libpq-dev_11.9-0+deb10u1_amd64.deb ...
Unpacking libpq-dev (11.9-0+deb10u1) ...
Setting up libpq5:amd64 (11.9-0+deb10u1) ...
Setting up libpq-dev (11.9-0+deb10u1) ...
Processing triggers for libc-bin (2.28-10) ...

Now we we’re going re-run the previous command, I’m skipping the output of a successful installation. At this point we need to restart the contianer or more the apache2 service. The container uses a apache2 to running in foreground, however, apache2 can be reload via the apache2ctl command without the neext to restart the whole container anew, awesome!

The next look on the database creation page of MediaWiki shows that postgresql is a choice now.

Continue to the MediaWiki installation

One great thing about the installation route of Media Wiki is that their asking for the database user. Gosh this is done right ;-)

One thing during the installation is that the tables are created twice, why? Anyway seems to work just fine.

After the database user creation is completed the next step is to configure the Wiki, I choose Priavte Wiki with the following Extensions:

Once the installation is completed you will download a LocalSettings.php file that needs to be deploy into the webroot of the MediaWiki container.

docker cp Downloads/LocalSettings.php docker-mediawiki_mediawiki_1:/var/www/html/LocalSettings.php

And we’re done with the installation at first! There are some addtional settings that needs to configure that is to allow file upoads and disable Caching (to few requests). Next post is how to automate this a bit better in context of the image creation

best regards,

€dit: For some reason the post was mixed up because of a copy and post fuck up ;-(, fixed now.