MediaWiki Setup Guide Portainer-Docker-251215-00
MediaWiki Setup Guide (Portainer & Docker)
This guide documents how to deploy, configure, and secure a MediaWiki instance using Portainer and Docker Compose. Designed as a general tutorial for any user, it walks through the process of setting up a wiki from scratch. It covers initial deployment, resolving common extension folder issues, and applying production configurations (using wiki.gi7b.org as the example domain).
Reference: Official MediaWiki Docker Image https://hub.docker.com/_/mediawiki
1. Prerequisites
Before starting, ensure you have:
- Docker & Docker Compose installed on your host (Debian/Ubuntu/Windows).
- Portainer installed and running (optional but recommended).
- A domain name (e.g., wiki.gi7b.org) pointing to your server's IP.
2. Host Folder Setup
Create a dedicated folder for your stack on the Docker host. This path is critical as it will store your configuration and extensions.
# Run on host terminal sudo mkdir -p /opt/stacks/mediawiki sudo mkdir -p /opt/stacks/mediawiki/extensions cd /opt/stacks/mediawiki
3. Deployment (Portainer / Docker Compose)
Use the following YAML configuration.
In Portainer:
- Go to Stacks → Add stack.
- Name it mediawiki.
- Paste the configuration below into the Web editor.
- Click Deploy the stack.
docker-compose.yml
services:
mediawiki:
image: mediawiki
container_name: mediawiki
restart: always
ports:
- 8191:80
depends_on:
- database
volumes:
- 251029_images:/var/www/html/images
# EXTENSIONS: Mounts host folder to container (Requires "Magic Command" step below)
- /opt/stacks/mediawiki/extensions:/var/www/html/extensions
# CONFIG: Uncomment the line below AFTER generating LocalSettings.php
# - /opt/stacks/mediawiki/LocalSettings.php:/var/www/html/LocalSettings.php:ro
database:
image: mariadb
container_name: mediawiki-db
restart: always
environment:
MYSQL_DATABASE: wiki
MYSQL_USER: wiki
MYSQL_PASSWORD: wiki
MYSQL_ROOT_PASSWORD: wiki
volumes:
- 251029_db:/var/lib/mysql
volumes:
251029_images:
251029_db:
4. First-Time Setup Wizard
- Open http://localhost:8191 (or your server IP:8191).
- Follow the prompts. When asked for Database Settings, use:
- Host: database
- Name: wiki
- User: wiki
- Password: wiki
- Complete the wizard and Download LocalSettings.php to your computer.
5. Fixing Extensions (The "Magic Command")
Crucial Step: Because we mounted a volume to /extensions, the container's default extensions (VisualEditor, WikiEditor, etc.) are hidden. We must copy them from the image to the host.
Run this on your Host Terminal:
docker run --rm --entrypoint tar mediawiki -c -C /var/www/html/extensions . | tar -x -C /opt/stacks/mediawiki/extensions
Download Mermaid (External Extension):
cd /opt/stacks/mediawiki/extensions
git clone [https://github.com/SemanticMediaWiki/Mermaid.git](https://github.com/SemanticMediaWiki/Mermaid.git) Mermaid
Verify the folder content: You should see a mix of default extensions and Mermaid:
ls -F /opt/stacks/mediawiki/extensions/
Output should look like this:
AbuseFilter/ CiteThisPage/ Echo/ Interwiki/ Mermaid/ PageImages/ README SpamBlacklist/ TextExtracts/ WikiEditor/
CategoryTree/ CodeEditor/ Gadgets/ Linter/ MultimediaViewer/ ParserFunctions/ ReplaceText/ SyntaxHighlight_GeSHi/ Thanks/
CheckUser/ ConfirmEdit/ ImageMap/ LoginNotify/ Nuke/ PdfHandler/ Scribunto/ TemplateData/ TitleBlacklist/
Cite/ DiscussionTools/ InputBox/ Math/ OATHAuth/ Poem/ SecureLinkFixer/ TemplateStyles/ VisualEditor/
6. Configuring LocalSettings.php
Move the downloaded LocalSettings.php to /opt/stacks/mediawiki/LocalSettings.php.
Edit the file (sudo nano /opt/stacks/mediawiki/LocalSettings.php) and make the following changes:
A. Set the Custom Domain
Find the $wgServer line (around line 30) and change it to your actual domain:
## The protocol and server name to use in fully-qualified URLs $wgServer = "[https://wiki.gi7b.org](https://wiki.gi7b.org)";
B. Add Permissions & Extensions
Paste this block at the very bottom of the file to enable security and extensions.
# -----------------------------------------------------------------------
# CUSTOM PERMISSIONS & EXTENSIONS
# -----------------------------------------------------------------------
# 1. SECURITY: Prevent anonymous editing and account creation
$wgGroupPermissions['*']['edit'] = false;
$wgGroupPermissions['*']['createaccount'] = false;
# 2. BUNDLED EXTENSIONS (Included in Docker image)
wfLoadExtension( 'WikiEditor' );
wfLoadExtension( 'VisualEditor' );
wfLoadExtension( 'CodeEditor' );
wfLoadExtension( 'SyntaxHighlight_GeSHi' );
wfLoadExtension( 'Cite' );
wfLoadExtension( 'InputBox' );
wfLoadExtension( 'Scribunto' );
wfLoadExtension( 'AbuseFilter' );
wfLoadExtension( 'Gadgets' );
wfLoadExtension( 'ParserFunctions' );
wfLoadExtension( 'Interwiki' );
# 3. EXTERNAL EXTENSIONS (Must be manually downloaded to /extensions folder)
wfLoadExtension( 'Mermaid' );
# 4. VISUALEDITOR CONFIGURATION
# Enable by default for everyone
$wgDefaultUserOptions['visualeditor-enable'] = 1;
# Allow VE to work in Docker containers (Fixes "Error contacting Parsoid")
$wgVisualEditorParsoidForwardCookies = true;
# 5. LUA CONFIGURATION (Required for Scribunto)
$wgScribuntoDefaultEngine = 'luastandalone';
7. Apply Changes
- Mount the settings: In Portainer, go to the Stack Editor and uncomment the LocalSettings.php line.
- Update the Stack: Click "Update the stack".
- Run Database Update: Run this command to initialize tables for the new extensions: docker exec -it mediawiki php maintenance/update.php --quick
Your wiki is now live at https://wiki.gi7b.org with VisualEditor and Mermaid enabled!