108Mediawiki - amagerard/Docker GitHub Wiki

Docker/Home

RedHat/Docker.

1- Docker 2- Firewall 3- Portainer 4- Drupal 5- Joomla
6-Wordpress 7-Xwiki 8- Mediawiki
Casaos Zimaos

8. Mediawiki.

MediaWiki is a wiki engine for the web.

This procedure is based on this example.

Docker server ip :192.168.60.55/24
Your username: teacher
Your home directory:/home/teacher

8.1 Create Network and Volumes with Portainer.

Open Portainer for create network and volumes.
http://192.168.60.55:9000

Click on Environments Local.

8.1.1 Each Mediawiki instance has its container.

  • cnt_mki_wb_number.
  • cnt_mki_db_number.

Containers will be created from the docker compose command line.

8.1.2 Each Mediawiki instance has its network.

  • net_mki_number.

Create net_mki_1.

Select Networks.  
Add network.  
Name : net_mki_1  
Add Driver options:  
Name : com.docker.network.bridge.name   value : net_mki_1  
Create the network.  

Name: com.docker.network.bridge.name value : net_mki_1 is not specified, docker will give it a name as br-XXXX.

8.1.3 Each Mediawiki instance has its volume.

  • vol_mki_wb_number.
  • vol_mki_db_number.

Create these volumes.

Select Volumes.  
Add volume.  
Name: vol_mki_wb_1  
Create the volume.  
Add the volume.  
Name: vol_mki_db_1  
Create the volume.  

8.1.4 Information.

Command lines to create the netwok and volumes without portainer.
docker network create --opt com.docker.network.bridge.name=net_mki_1 net_mki_1
docker volume create vol_mki_wb_1
docker volume create vol_mki_db_1

8.2 Give permissions to www-dock and mysql-dock for volumes.

chown -R www-dock:www-dock /var/lib/docker/volumes/vol_mki_wb_1
chown -R mysql-dock:mysql-dock /var/lib/docker/volumes/vol_mki_db_1

8.3 Edit a yaml script for Mediawiki.

Logging with your username.
mkdir /home/teacher/mediawiki
vi /home/teacher/mediawiki/instance_mediawiki_1.yaml

# 2025, January  
# replace number  by 1 or 2 or ... until 9  
# example n = 1  
# port published wb = 8081  
# port published db = 33771  
# ip = 192.168.60.55  
# your username is teacher  
# you must create network net_mki_1    from portainer before installing mediawiki.  
# you must create volume vol_mki_wb_1  from portainer before installing mediawiki.  
# you must create volume vol_mki_db_1  from portainer before installing mediawiki.  
# you must create  mediawiki_1 folder  under /home/teacher/docker/files before installing mediawiki  
#  
# mkdir -p  /home/teacher/docker/files/mediawiki_1/  
#  
#  
# you cannot  delete   /home/teacher/docker/files/mediawiki_1  
#  
# Be careful with the tab, the indentation is 4 characters.  
#  
name: mediawiki_1  ## change  n of mediawiki_n  
services:  
    mediawiki:  
        cpu_shares: 90  
        command: []  
        container_name: cnt_mki_wb_1  ## change  n  of cnt_mki_wb_n  
        depends_on:  
            mediawikidb:  
                condition: service_started  
                restart: true  
                required: true  
        deploy:  
            resources:  
                limits:  
                    memory: 2048M  
        environment: []  
        hostname: cnt_mki_wb_1  ## change n to cnt_mki_wb_n  
        image: mediawiki:latest  
        links:  
            - mediawikidb:mariadb  
        ports:  
            - target: 80  
              published: '8081'  ## change  n of 808n  
              protocol: tcp  
        restart: always  
        volumes:  
            - /var/lib/docker/volumes/vol_mki_wb_1/_data:/var/www/html/images # create volume from portainer and change  n of vol_mki_wb_n  
            # 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.  
            # put newly created LocalSettings.php in the /home/teacher/docker/files/mediawiki_1/ and remove the "#"  
           #- /home/teacher/docker/files/mediawiki_1/LocalSettings.php:/var/www/html/LocalSettings.php  
  
        user: 2001:2001 ## www-dock uid:gid  
        devices: []  
        cap_add: []  
        network_mode: net_mki_1 # create network  from portainer and change  n of net_mki_1  
        privileged: false  
    mediawikidb:  
        cpu_shares: 90  
        container_name: cnt_mki_db_1  ## change  n  of cnt_mki_db_n  
        command: []  
        deploy:  
            resources:  
                limits:  
                    memory: 2048M  
        environment:  
            - MYSQL_DATABASE=my_wiki  
            - MYSQL_USER=wikiuser  
            - MYSQL_PASSWORD=password  # as you want  
            - MYSQL_RANDOM_ROOT_PASSWORD=yes  
        hostname: cnt_mki_db_1 ## change  n of cnt_mki_db_n  
        image: mariadb:latest  
        ports:  
            - target: 3306  
        published: '33771'  ## change  n to  3377n  
        protocol: tcp  
        restart: always  
        volumes:  
            - /var/lib/docker/volumes/vol_mki_db_1/_data:/var/lib/mysql  ## create volume from portainer and change  n of vol_mki_db_n  
        user: 2002:2002  ## mysql-dock uid:gid  
        devices: []  
        cap_add: []  
        network_mode: net_mki_1  # create network  from portainer and change  n of net_mki_1  
        privileged: false  

Information.
If you want to change your Mediawiki instance in 2,
Edit this file and replace _1 by _2.
Then replace the port 8081 by 8082
and 33771 by 33772.
You will need to create a mediawiki_2 folder under /home/teacher/docker/files/
because the LocalSettings file will be different.

8.4 First Installation for initial setup.

Installing Mediawiki is done in 2 steps:

  • 1- After initial setup, download LocalSettings.php to the same directory as /home/teacher/docker/files/mediawiki_1.
  • 2- Uncomment the following line.
    - /home/teacher/docker/files/mediawiki_1/LocalSettings.php:/var/www/html/LocalSettings.php
    from instance_mediawiki_1.yaml

First installation of mediawiki.

docker compose -f /home/teacher/mediawiki/instance_mediawiki_1.yaml up

Do not stop containers.
Do not do Ctrl+C to stop.

8.5 Firewall.

Open another console terminal.

Find your interface for network net_mki_1.
The gateway is displayed in Portainer Networks.
Example:
the net_mki_1 gateway is 172.18.0.1/16.
Network interface is net_mki_1.

ifconfig

net_mki_1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500  
        inet 172.18.0.1  netmask 255.255.0.0  broadcast 172.18.255.255  
        ether 02:42:6a:71:3d:51  txqueuelen 0  (Ethernet)  
        RX packets 10742  bytes 23229052 (22.1 MiB)  
        RX errors 0  dropped 0  overruns 0  frame 0  
        TX packets 12571  bytes 5854522 (5.5 MiB)  
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0  

Add rules on firewall.
iptables -t nat -A POSTROUTING ! -o net_mki_1 -s 172.18.0.0/16 -j MASQUERADE
ufw route allow in on net_mki_1 out on eth0 to any from any
ufw allow in from any to any port 8081

The postrouting iptable rule disappears after restarting the server.
The solution is to add the rule in crontab.
Add postrouting iptable in /opt/docker/postrouting_sh.

vi /opt/docker/postrouting_sh

iptables -t nat -A POSTROUTING ! -o net_mki_1  -s 172.18.0.0/16 -j MASQUERADE  

Don't forget to delete line if you no longer use this iptable rule.

Information.
To delete an iptable postrouting rule without reboot.
Postrouting line number.
iptables --list -v --line-numbers -t nat
Remove rule ( 1 is the line number).
iptables -t nat -D POSTROUTING 1

8.6 First access Mediawiki for initial setup.

http://192.168.60.55:8081.

First page :setup the wiki first.
Language:
Your Language :en - English.
Wiki language :en - English
All is OK : Continue.
Connect to database:
Database type:MariasDB.
Database host:cnt_mki_db_1.
Identify this wiki:
Database name:my_wiki.
User account for installation:
Database username:wikiuser.
Database password:password.
Continue.
Database settings:
Use the same account as for installation.
Continue.
Name:
Name of wiki:mybeautifulweb.
Administrator account:
Your username: adminwiki.
Password (10 characters) :as you want.
Email address:as you want;
I'm bored already, just install the wiki.
Install
Continue for Begin the installation.
Install database.
Database was successfully setup.
Continue.
The installer has generated a LocalSettings.php file.
Your LocalSettings.php file is located in your browser's downloads folder.

8.7 LocalSettings.php.

Log in with your username.

Create mediawiki_1 folder.
mkdir -p /home/teacher/docker/files/mediawiki_1.
Copy LocalSettings.php to /home/teacher/docker/files/mediawiki_1.
Add at the end of LocalSettings.php file.
vi /home/teacher/docker/files/mediawiki_1/LocalSettings.php

# Add  extensions  
wfLoadExtensions( [ 'Cite', 'CiteThisPage', 'ParserFunctions', 'ConfirmEdit', 'InputBox', 'Gadgets', 'ImageMap', 'Nuke' , 'ParserFunctions','PdfHandler', 'SpamBlacklist', 'Poem', 'TitleBlacklist'] );  
  
## Editor VisualEditor  
wfLoadExtension( 'VisualEditor' );  
  
## WikiEditor  
wfLoadExtension( 'WikiEditor' );  
$wgHiddenPrefs[] = 'usebetatoolbar';  
$wgDefaultUserOptions['showtoolbar'] = true;  
$wgDefaultUserOptions['usebetatoolbar'] = 1;  
  
## SyntaxHighlight  
wfLoadExtension( 'SyntaxHighlight_GeSHi' );  

Change UTC.
Find your Time Zone.
timedatectl list-timezones
Example: "Australia/Sydney"
vi /home/teacher/docker/files/mediawiki_1/LocalSettings.php

# Time zone  
#$wgLocaltimezone = "UTC";  
$wgLocaltimezone = "Autralia/Sydney";  

Enable upload.
Change $wgEnableUploads false to true.
vi /home/teacher/docker/files/mediawiki_1/LocalSettings.php

$wgEnableUploads = true;  

8.8 Second install mediawiki.

Uncomment the following line - /home/teacher/docker/files/mediawiki_1/LocalSettings.php:/var/www/html/LocalSettings.php
from instance_mediawiki_1.yaml.

vi /home/teacher/mediawiki/instance_mediawiki_1.yaml

Be careful with identation (6).

#  
     - /home/teacher/docker/files/mediawiki_2/LocalSettings.php:/var/www/html/LocalSettings.php  

From first terminal console.

Stop Mediawiki containers.
Ctrl +C
Do the command line.
docker compose -f /home/teacher/mediawiki/instance_mediawiki_1.yaml up
Stop Mediawiki containers.
Ctrl +C

8.9 Attach volumes with containers.

On portainer, by default the volumes are marked Unused.

Open Portainer.
http://192.168.60.55:9000

Click on Environments Local.

Select Container cnt_mki_wb_1.
Click on cnt_mki_wb_1.
Click Duplicate/Edit.
Advanced container settings.
Click on Volumes.
Volumes mapping.
Choose container /var/www/html/images.
Click on Volume.
Select a Volume.
Choose vol_mki_wb_1 - local.
Click on Deploy the container.
Click on Replace.

Select containers cnt_mki_db_1.
Click on cnt_mki_db_1.
Click Duplicate/Edit.
Advanced container settings.
Click on Volumes.
Volumes mapping.
Choose container /var/lib/mysql.
Click on Volume.
Select a Volume.
Choose vol_mki_db_1 - local.
Click on Deploy the container.
Click on Replace.

8.9 Give permissions to www-dock for its volume.

www-dock permissions on vol_mki_wb_1 have been removed.
chown -R www-dock:www-dock /var/lib/docker/volumes/vol_mki_wb_1

8.10 Second access Mediawiki.

http://192.168.60.55:8081.
Log in adminwiki.
Mediawiki is ready.