MediaWiki Setup Guide Portainer-Docker-251215-00: Difference between revisions
Justinaquino (talk | contribs) No edit summary |
Justinaquino (talk | contribs) No edit summary |
||
| Line 1: | Line 1: | ||
= MediaWiki Setup Guide (Portainer & Docker) = | = 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 | This guide documents how to deploy, configure, and secure a '''MediaWiki''' instance using '''Portainer''' and '''Docker Compose'''. Designed as a general tutorial, it walks through the process of setting up a wiki from scratch, resolving common extension folder issues, and applying production configurations. | ||
'''Reference:''' Official MediaWiki Docker Image [https://hub.docker.com//mediawiki https://hub.docker.com//mediawiki] | '''Reference:''' Official MediaWiki Docker Image [https://hub.docker.com//mediawiki https://hub.docker.com//mediawiki] | ||
| Line 9: | Line 9: | ||
Before starting, ensure you have: | Before starting, ensure you have: | ||
'''Docker & Docker Compose''' | '''Docker & Docker Compose''': [https://docs.docker.com/engine/install/ Installation Guide] | ||
'''Portainer CE''': [https://docs.portainer.io/start/install-ce/server/docker/linux Docker Standalone Install Guide] | |||
''' | '''Domain & Cloudflare Setup''': [https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/get-started/create-remote-tunnel/ Cloudflare Tunnel (Cloudflared) Setup Guide] | ||
'''NGINX Reverse Proxy''': [https://nginxproxymanager.com/guide/#quick-setup Nginx Proxy Manager Setup] | |||
'''NGINX Reverse Proxy''' | |||
== 2. Host Folder Setup == | == 2. Host Folder Setup == | ||
| Line 43: | Line 32: | ||
== 3. Deployment (Portainer / Docker Compose) == | == 3. Deployment (Portainer / Docker Compose) == | ||
=== In Portainer === | |||
=== In Portainer | |||
Go to '''Stacks''' → '''Add stack'''. | Go to '''Stacks''' → '''Add stack'''. | ||
Name it | Name it mediawiki. | ||
Paste the configuration below into the Web editor. | Paste the configuration below into the Web editor. | ||
| Line 56: | Line 43: | ||
=== docker-compose.yml === | === docker-compose.yml === | ||
<syntaxhighlight lang="yaml"> | <syntaxhighlight lang="yaml"> | ||
services: | services: | ||
| Line 93: | Line 79: | ||
== 4. First-Time Setup Wizard == | == 4. First-Time Setup Wizard == | ||
Open | Open http://[YOUR_SERVER_IP]:8595 in your browser. | ||
Follow the prompts. When asked for '''Database Settings''', use: | Follow the prompts. When asked for '''Database Settings''', use: | ||
#* '''Host:''' | #* '''Host:''' database | ||
#* '''Name:''' | #* '''Name:''' mediawiki | ||
#* '''User:''' | #* '''User:''' mediawiki | ||
#* '''Password:''' | #* '''Password:''' mediawiki | ||
Complete the wizard and '''Download LocalSettings.php''' to your computer. | Complete the wizard and '''Download LocalSettings.php''' to your computer. | ||
| Line 106: | Line 92: | ||
== 5. Fixing Extensions (The "Magic Command") == | == 5. Fixing Extensions (The "Magic Command") == | ||
'''Crucial Step:''' Because we mounted a volume to | '''Crucial Step:''' Because we mounted a volume to /extensions, the container's default extensions (VisualEditor, SyntaxHighlight_GeSHi, etc.) are hidden. We must copy them from the image to the host. | ||
=== Step A: Extract Extensions === | === Step A: Extract Extensions === | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
docker run --rm --entrypoint tar mediawiki -c -C /var/www/html/extensions . | tar -x -C /opt/stacks/mediawiki/extensions | docker run --rm --entrypoint tar mediawiki -c -C /var/www/html/extensions . | tar -x -C /opt/stacks/mediawiki/extensions | ||
| Line 117: | Line 100: | ||
=== Step B: Fix Permissions for Code Highlighting === | === Step B: Fix Permissions for Code Highlighting === | ||
The SyntaxHighlight_GeSHi extension requires a specific Python file (pygmentize) to be executable. | |||
The | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
chmod a+x /opt/stacks/mediawiki/extensions/SyntaxHighlight_GeSHi/pygments/pygmentize | chmod a+x /opt/stacks/mediawiki/extensions/SyntaxHighlight_GeSHi/pygments/pygmentize | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Step C: Add External Extensions === | === Step C: Add External Extensions === | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
cd /opt/stacks/mediawiki/extensions | cd /opt/stacks/mediawiki/extensions | ||
git clone https://github.com/SemanticMediaWiki/Mermaid.git Mermaid | git clone https://github.com/SemanticMediaWiki/Mermaid.git Mermaid | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== 6. Configuring LocalSettings.php == | == 6. Configuring LocalSettings.php == | ||
Move the downloaded | Move the downloaded LocalSettings.php to /opt/stacks/mediawiki/LocalSettings.php. | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
sudo nano /opt/stacks/mediawiki/LocalSettings.php | sudo nano /opt/stacks/mediawiki/LocalSettings.php | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== A. Set the Custom Domain === | === A. Set the Custom Domain === | ||
Find the $wgServer line and change it to your actual domain: | |||
Find the | |||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
$wgServer = "https://wiki.gi7b.org"; | $wgServer = "https://wiki.gi7b.org"; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== B. Add Permissions & Extensions === | === B. Add Permissions & Extensions === | ||
Paste this block at the '''very bottom''' of the file: | |||
Paste this block at the '''very bottom''' of the file | |||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
/* ----------------------------------------------------------------------- | |||
----------------------------------------------------------------------- | |||
CUSTOM PERMISSIONS & EXTENSIONS | CUSTOM PERMISSIONS & EXTENSIONS | ||
----------------------------------------------------------------------- */ | |||
----------------------------------------------------------------------- | |||
1. SECURITY: Prevent anonymous editing and account creation | 1. SECURITY: Prevent anonymous editing and account creation | ||
| Line 183: | Line 137: | ||
$wgGroupPermissions['']['createaccount'] = false; | $wgGroupPermissions['']['createaccount'] = false; | ||
2. BUNDLED EXTENSIONS | 2. BUNDLED EXTENSIONS | ||
wfLoadExtension( 'WikiEditor' ); | wfLoadExtension( 'WikiEditor' ); | ||
| Line 197: | Line 151: | ||
wfLoadExtension( 'Interwiki' ); | wfLoadExtension( 'Interwiki' ); | ||
3. EXTERNAL EXTENSIONS | 3. EXTERNAL EXTENSIONS | ||
wfLoadExtension( 'Mermaid' ); | wfLoadExtension( 'Mermaid' ); | ||
4. VISUALEDITOR CONFIGURATION | 4. VISUALEDITOR CONFIGURATION | ||
$wgDefaultUserOptions['visualeditor-enable'] = 1; | $wgDefaultUserOptions['visualeditor-enable'] = 1; | ||
$wgVisualEditorParsoidForwardCookies = true; | $wgVisualEditorParsoidForwardCookies = true; | ||
| Line 214: | Line 163: | ||
$wgScribuntoDefaultEngine = 'luastandalone'; | $wgScribuntoDefaultEngine = 'luastandalone'; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== 7. Apply Changes == | == 7. Apply Changes == | ||
'''Mount the settings | '''Mount the settings''': In Portainer, go to the Stack Editor and '''uncomment''' the LocalSettings.php line. | ||
'''Update the Stack | '''Update the Stack''': Click "Update the stack". | ||
'''Run Database Update | '''Run Database Update''': | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
docker exec -it mediawiki php maintenance/update.php --quick | docker exec -it mediawiki php maintenance/update.php --quick | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== 8. Email Configuration and Admin Setup == | == 8. Email Configuration and Admin Setup == | ||
=== 1. | === 1. SMTP Logic === | ||
MediaWiki must be able to send emails for account confirmation and resets. Authentication must work with '''Gmail / Google Workspace'''. | |||
MediaWiki must be able to | |||
Authentication must work with '''Gmail / Google Workspace'''. | |||
=== 2. Google App Password === | |||
Go to Google Account → Security → App passwords. | |||
'''Critical Detail:''' MediaWiki must receive the password '''without spaces'''. | |||
Displayed: xxxx xxxx xxxx xxxx → Input: xxxxxxxxxxxxxxxx | |||
: | |||
=== 3. SMTP Configuration === | |||
Add this to LocalSettings.php: | |||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
$wgEnableEmail = true; | $wgEnableEmail = true; | ||
| Line 322: | Line 201: | ||
'port' => 465, | 'port' => 465, | ||
'auth' => true, | 'auth' => true, | ||
'username' => 'admin@gi7b.org', | 'username' => 'admin@gi7b.org', // REAL mailbox | ||
'password' => 'APP_PASSWORD_NO_SPACES', // Your Google App Password | 'password' => 'APP_PASSWORD_NO_SPACES', // Your Google App Password | ||
]; | ]; | ||
$wgPasswordSender = 'info@gi7b.org'; // ALIAS is fine here | $wgPasswordSender = 'info@gi7b.org'; // ALIAS is fine here | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== | === 4. Promote Account to Admin === | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
docker exec -it mediawiki php maintenance/createAndPromote.php --sysop --bureaucrat YourUsername | docker exec -it mediawiki php maintenance/createAndPromote.php --sysop --bureaucrat YourUsername | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== 9. Brute Force Protection == | |||
== 9. | |||
Add throttling to LocalSettings.php: | |||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
| Line 374: | Line 225: | ||
== 10. How to use Code Blocks == | == 10. How to use Code Blocks == | ||
'''Source Editor:''' Use the tag: | '''Source Editor:''' Use the tag: | ||
< | <pre> | ||
<syntaxhighlight lang="python" copy> | <syntaxhighlight lang="python" copy> | ||
print("This code has a copy button!") | print("This code has a copy button!") | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</ | </pre> | ||
: | == 11. Quick Guide: Adding Extensions == | ||
'''Download''': | |||
''' | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
cd /opt/stacks/mediawiki/extensions | cd /opt/stacks/mediawiki/extensions | ||
git clone https://www.google.com/search?q=https://gerrit.wikimedia.org/r/mediawiki/extensions/ExtensionName | |||
</syntaxhighlight> | </syntaxhighlight> | ||
''' | '''Enable''': Add wfLoadExtension( 'ExtensionName' ); to LocalSettings.php. | ||
'''Update''': | |||
'' | |||
'' | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
docker exec -it mediawiki php maintenance/update.php --quick | docker exec -it mediawiki php maintenance/update.php --quick | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 09:43, 26 January 2026
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, it walks through the process of setting up a wiki from scratch, resolving common extension folder issues, and applying production configurations.
Reference: Official MediaWiki Docker Image https://hub.docker.com//mediawiki
1. Prerequisites
Before starting, ensure you have:
Docker & Docker Compose: Installation Guide
Portainer CE: Docker Standalone Install Guide
Domain & Cloudflare Setup: Cloudflare Tunnel (Cloudflared) Setup Guide
NGINX Reverse Proxy: Nginx Proxy Manager Setup
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)
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:
- 8595:80
depends_on:
- database
volumes:
- 230912_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: mediawiki
MYSQL_USER: mediawiki
MYSQL_PASSWORD: mediawiki
MYSQL_ROOT_PASSWORD: mediawiki
volumes:
- 230912_db:/var/lib/mysql
volumes:
230912_images:
230912_db:
4. First-Time Setup Wizard
Open http://[YOUR_SERVER_IP]:8595 in your browser.
Follow the prompts. When asked for Database Settings, use:
- Host: database
- Name: mediawiki
- User: mediawiki
- Password: mediawiki
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, SyntaxHighlight_GeSHi, etc.) are hidden. We must copy them from the image to the host.
Step A: Extract Extensions
docker run --rm --entrypoint tar mediawiki -c -C /var/www/html/extensions . | tar -x -C /opt/stacks/mediawiki/extensions
Step B: Fix Permissions for Code Highlighting
The SyntaxHighlight_GeSHi extension requires a specific Python file (pygmentize) to be executable.
chmod a+x /opt/stacks/mediawiki/extensions/SyntaxHighlight_GeSHi/pygments/pygmentize
Step C: Add External Extensions
cd /opt/stacks/mediawiki/extensions
git clone https://github.com/SemanticMediaWiki/Mermaid.git Mermaid
6. Configuring LocalSettings.php
Move the downloaded LocalSettings.php to /opt/stacks/mediawiki/LocalSettings.php.
sudo nano /opt/stacks/mediawiki/LocalSettings.php
A. Set the Custom Domain
Find the $wgServer line and change it to your actual domain:
$wgServer = "https://wiki.gi7b.org";
B. Add Permissions & Extensions
Paste this block at the very bottom of the file:
/* -----------------------------------------------------------------------
CUSTOM PERMISSIONS & EXTENSIONS
----------------------------------------------------------------------- */
1. SECURITY: Prevent anonymous editing and account creation
$wgGroupPermissions['']['edit'] = false;
$wgGroupPermissions['']['createaccount'] = false;
2. BUNDLED EXTENSIONS
wfLoadExtension( 'WikiEditor' );
wfLoadExtension( 'VisualEditor' );
wfLoadExtension( 'CodeEditor' );
wfLoadExtension( 'SyntaxHighlight_GeSHi' ); # REQUIRED for Code Blocks
wfLoadExtension( 'Cite' );
wfLoadExtension( 'InputBox' );
wfLoadExtension( 'Scribunto' );
wfLoadExtension( 'AbuseFilter' );
wfLoadExtension( 'Gadgets' );
wfLoadExtension( 'ParserFunctions' );
wfLoadExtension( 'Interwiki' );
3. EXTERNAL EXTENSIONS
wfLoadExtension( 'Mermaid' );
4. VISUALEDITOR CONFIGURATION
$wgDefaultUserOptions['visualeditor-enable'] = 1;
$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:
docker exec -it mediawiki php maintenance/update.php --quick
8. Email Configuration and Admin Setup
1. SMTP Logic
MediaWiki must be able to send emails for account confirmation and resets. Authentication must work with Gmail / Google Workspace.
2. Google App Password
Go to Google Account → Security → App passwords.
Critical Detail: MediaWiki must receive the password without spaces.
Displayed: xxxx xxxx xxxx xxxx → Input: xxxxxxxxxxxxxxxx
3. SMTP Configuration
Add this to LocalSettings.php:
$wgEnableEmail = true;
$wgEnableUserEmail = true;
$wgSMTP = [
'host' => 'ssl://smtp.gmail.com',
'IDHost' => 'wiki.gi7b.org',
'port' => 465,
'auth' => true,
'username' => 'admin@gi7b.org', // REAL mailbox
'password' => 'APP_PASSWORD_NO_SPACES', // Your Google App Password
];
$wgPasswordSender = 'info@gi7b.org'; // ALIAS is fine here
4. Promote Account to Admin
docker exec -it mediawiki php maintenance/createAndPromote.php --sysop --bureaucrat YourUsername
9. Brute Force Protection
Add throttling to LocalSettings.php:
Login attempt throttling
$wgRateLimits['user']['login'] = [ 5, 60 ]; // 5 attempts per minute
$wgRateLimits['ip']['login'] = [ 20, 300 ]; // 20 attempts per 5 minutes
10. How to use Code Blocks
Source Editor: Use the tag:
<syntaxhighlight lang="python" copy>
print("This code has a copy button!")
</syntaxhighlight>
11. Quick Guide: Adding Extensions
Download:
cd /opt/stacks/mediawiki/extensions
git clone https://www.google.com/search?q=https://gerrit.wikimedia.org/r/mediawiki/extensions/ExtensionName
Enable: Add wfLoadExtension( 'ExtensionName' ); to LocalSettings.php.
Update:
docker exec -it mediawiki php maintenance/update.php --quick