Mediawiki-docker: Difference between revisions
Appearance
| Line 145: | Line 145: | ||
= Fix permissions = | = Fix permissions = | ||
usually www-data UID 33. | |||
<syntaxhighlight lang='sh'> | |||
id www-data | |||
# uid=33(www-data) gid=33(www-data) groups=33(www-data) | |||
sudo chown -R 33:33 ~/mediawiki-docker/images ~/mediawiki-docker/extensions | sudo chown -R 33:33 ~/mediawiki-docker/images ~/mediawiki-docker/extensions | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 09:15, 10 October 2025
Directories
- Backup directory ~/backups
- Mediawiki directory ~/mediawiki-docker
Accounts
- DB account (defined in compose.yml and LocalSettings.php):
- database: wikidb ($wgDBname)
- user: ($wgDBuser)
- password: ($wgDBpassword)
- Mediawiki admin:
- Mediawiki user:
Note the mediawiki admin and user accounts are embedded in the SQL database.
Backup
Assume the mediawiki directory on the host is /var/www/html/wiki
- MySQL
mkdir ~/backups cd ~/backups sudo mysqldump -p wikidb > sql_backup_file
- images (no need for extensions/skins directories)
cp /var/www/html/wiki/LocalSettings.php ~/backups/LocalSettings.php cd /var/www/html/wiki tar -czf ~/backups/images.tar.gz images
Prepare host project folder for Docker
mkdir ~/mediawiki-docker/ cd ~/mediawiki-docker tar -xzvf ~/backups/images.tar.gz
compose.yml
Tips: Do not mount host's extensions and skins folders.
services:
db:
image: mariadb:10.11
container_name: mw_db
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ""
MYSQL_DATABASE: "wikidb"
MYSQL_USER: ""
MYSQL_PASSWORD: ""
volumes:
- ./db_data:/var/lib/mysql
#healthcheck:
# test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
# interval: 10s
# timeout: 5s
# retries: 5
mediawiki:
image: mediawiki:1.43.3
container_name: mw_web
depends_on:
- db
# condition: service_healthy
ports:
- "82:80"
volumes:
- ./images:/var/www/html/images
- ./extensions/Highlightjs_Integration:/var/www/html/extensions/Highlightjs_Integration:ro
- ./extensions/SimpleMathJax:/var/www/html/extensions/SimpleMathJax:ro
- ./LocalSettings.php:/var/www/html/LocalSettings.php:ro
- ./php.ini:/usr/local/etc/php/conf.d/mediawiki.ini:ro
restart: unless-stopped
Prepare LocalSettings.php for Docker
- Open your backed-up LocalSettings.php and change DB host/user/password to match docker-compose.yml:
- $wgServer has to be the exact URL you will access. For example, http://wiki.taichimd.us:82/ instead of http://localhost:82 even if I access the site from home
- Ensure the file contains the necessary wfLoadExtension() lines for the extensions you want enabled
$wgDBserver = ""; $wgDBname = ""; $wgDBuser = ""; $wgDBpassword = "ChangeThisWikiPass"; // set server and script path appropriately: $wgServer = "http://your.host.or.ip:82"; $wgScriptPath = ""; // usually empty when site is at webroot
Put the extensions in place
MultimediaViewer and WikiEditor are bundled in the mediawiki. We just need to load them in the LocalSettings.php file.
cd ~/mediawiki-docker/extensions git clone --depth 1 https://github.com/jmnote/SimpleMathJax.git SimpleMathJax git clone --depth 1 https://github.com/Nicolas01/Highlightjs_Integration.git
Ensure LocalSettings.php load these extensions.
wfLoadExtension( 'SimpleMathJax' ); wfLoadExtension( 'Highlightjs_Integration' ); wfLoadExtension( 'MultimediaViewer' ); wfLoadExtension( 'WikiEditor' );
Start containers and import DB
Replace $MYSQL_ROOT_PASSWORD with the actual root password you used in your MariaDB container:
cd ~/mediawiki-docker docker compose up -d db docker run --rm -v ~/backups:/backup --network container:mw_db mariadb:10.11 \ sh -c 'exec mysql -h 127.0.0.1 -u root -p"ChangeThisRootPass" wikidb < /backup/sql_backup_file' docker compose up -d mediawiki
Run MediaWiki updater (DB schema) inside the container
This may takes a longer time to run the first time.
docker compose exec mediawiki php /var/www/html/maintenance/update.php
Fix permissions
usually www-data UID 33.
id www-data # uid=33(www-data) gid=33(www-data) groups=33(www-data) sudo chown -R 33:33 ~/mediawiki-docker/images ~/mediawiki-docker/extensions
Verify & test
- Open http://http://your.host.or.ip:82/Special:Version — check MediaWiki version and enabled extensions.
- Upload a small image to File: to verify images/ mount works.
- Check Math rendering on a page with <math>...</math> (SimpleMathJax) and confirm highlight.js highlighting in a <syntaxhighlight> block.
- Confirm MultimediaViewer opens images in the lightbox.
Bonus: Chinese characters
sudo dpkg-reconfigure locales export LANG=en_US.UTF-8
Backup MYSQL
docker exec -i mw_db mysqldump -u root -p"$MYSQL_ROOT_PASSWORD" wikidb > ~/backups/wikidb_$(date +%F).sql # OR docker compose exec db mysqldump -u root -p"$MYSQL_ROOT_PASSWORD" wikidb > ~/backups/wikidb_$(date +%F).sql
Steps for upgrading 1.43.3 → 1.43.4
- Edit your compose.yml by changing the image tag from 1.43.3 to 1.43.4
- Pull the new image. docker compose pull mediawiki
- Restart with new version. docker compose up -d mediawiki
- Run update.php. docker compose exec mediawiki php maintenance/run.php update
- Verify and check the log. docker compose logs -f mediawiki