← All templates · Notes and wikis
Deploy MediaWiki in one click
The wiki software of Wikipedia: pages anyone can read, edited in the visual or the source editor
A self-hosted alternative to Confluence and Fandom.
What is MediaWiki?
MediaWiki is the free and open-source wiki software made by the Wikimedia Foundation for Wikipedia, and used by thousands of other wikis, from game and fan wikis to company knowledge bases. Pages link to each other by their titles, every edit is kept in the page's history and can be compared or reverted, and each page has a talk page for discussion. Templates, categories and the Special pages help to organise a large wiki, and its API lets bots and scripts read and edit.
Editors write in wikitext, MediaWiki's markup, or in VisualEditor, which edits a page as it looks. This template enables the extensions that come with MediaWiki, among them VisualEditor, WikiEditor, ParserFunctions, Cite, Scribunto for Lua modules, SyntaxHighlight and DiscussionTools, and the skins Vector, MonoBook, Timeless and MinervaNeue for phones.
This template runs MediaWiki's official image, version 1.46, with Apache and PHP, and its database in SQLite, which MediaWiki supports for small and medium wikis. The wiki is installed before it answers anyone, with the name, username and password you give; anyone can read it, only signed-in users edit, and accounts are made by the administrator.
Hosting MediaWiki on Pethost
- You sign in to Pethost with a passkey, GitHub or Google. No machine yet? You pick a plan, and the link waits until it is ready.
- New project opens at MediaWiki. You fill in what it asks for and click Create project: Site name, Username, Admin password.
- In a minute or two MediaWiki is live at its own address with HTTPS. Its secrets are made at random, and its data is in the nightly backup.
- It is a project like any other: you or your agent can change it, roll it back or restore it.
Questions about MediaWiki
Is MediaWiki free?
Yes. MediaWiki is open source under the GNU General Public License, version 2 or later, and free to use for any wiki, public or private. Wikipedia runs on the same software.
Does MediaWiki have a visual editor?
Yes. VisualEditor comes with MediaWiki and is enabled by this template: Edit opens a page as it looks, and Edit source opens its wikitext. Both save to the same page history.
How do I make my MediaWiki private?
Add $wgGroupPermissions['*']['read'] = false; to LocalSettings.php, in the data volume, and restart the project: then only signed-in users read. Special:UserLogin stays open, so editors can still sign in.
How do I add users to my wiki?
Sign in as the administrator and open Special:CreateAccount: give a username and a password, or an email address for a temporary one. Special:UserRights then gives a user the rights of a group, such as administrator.
Can I install MediaWiki extensions?
Yes. The extensions that ship with MediaWiki are enabled already. Another one is copied into the container's extensions folder and loaded with wfLoadExtension in LocalSettings.php; a change of the image replaces that folder, so keep the extensions you add in a volume of your own.
How much memory and disk does MediaWiki need?
MediaWiki is light: about 200 MB of memory, and its SQLite database grows with each page's history; uploads take what their files take. On Pethost the Starter plan is enough for it, with room for other apps beside it.
MediaWiki Docker Compose file
The template is this compose.yaml and the variables written into the project’s .env as it is created. Pethost runs the file as it is written.
Containers: mediawiki (mediawiki:1.46).
Volumes, in the nightly backup: data, images.
services:
mediawiki:
image: mediawiki:1.46
restart: unless-stopped
environment:
WIKI_URL: ${URL}
WIKI_NAME: ${WIKI_NAME}
ADMIN_USERNAME: ${ADMIN_USERNAME}
ADMIN_PASSWORD: ${ADMIN_PASSWORD}
# A new MediaWiki offers its installer, which makes the administrator, to whoever opens it
# first. So the wiki is installed here before Apache answers anyone: its SQLite database and
# LocalSettings.php in the data volume, the administrator from the fields. LocalSettings.php is
# written there only once the install has succeeded; a start that finds none puts what an
# earlier, failed install left aside in data/failed-<time> and installs again. Every start
# then runs MediaWiki's update, which a newer image of the line may need.
command:
- sh
- -c
- |
set -e
cd /var/www/html
if [ ! -f /var/www/data/LocalSettings.php ]; then
if ls /var/www/data/*.sqlite >/dev/null 2>&1; then
aside=/var/www/data/failed-$$(date +%s)
mkdir "$$aside"
mv /var/www/data/*.sqlite* "$$aside"/
fi
rm -rf /var/www/data/install
mkdir -p /var/www/data/install
php maintenance/run.php install --dbtype=sqlite --dbpath=/var/www/data --dbname=wiki \
--server="$$WIKI_URL" --scriptpath= --lang=en --pass="$$ADMIN_PASSWORD" \
--with-extensions --confpath=/var/www/data/install "$$WIKI_NAME" "$$ADMIN_USERNAME"
cat /var/www/data/install/LocalSettings.php - > /var/www/data/LocalSettings.php <<'PHP'
# The wiki's name and address are the project's .env's, read at every start.
$$wgSitename = getenv('WIKI_NAME') ?: $$wgSitename;
$$wgMetaNamespace = false;
$$wgServer = getenv('WIKI_URL') ?: $$wgServer;
# MediaWiki is at the address's root, and its pages at /wiki/Page_name: Apache sends every
# address that is no file to index.php.
$$wgScriptPath = '';
$$wgResourceBasePath = $$wgScriptPath;
$$wgArticlePath = '/wiki/$$1';
# Anyone reads; only signed-in users edit, and only an administrator makes accounts, at
# Special:CreateAccount.
$$wgGroupPermissions['*']['createaccount'] = false;
$$wgGroupPermissions['*']['edit'] = false;
# MediaWiki's flower beside the wiki's name, until a logo of the wiki's own is set here.
$$wgLogos = ['icon' => "$$wgResourceBasePath/resources/assets/mediawiki_compact.svg", '1x' => "$$wgResourceBasePath/resources/assets/mediawiki.png"];
# Uploaded files are kept in the images volume.
$$wgEnableUploads = true;
# The visitor's address is in X-Forwarded-For, from the machine's proxy.
$$wgUsePrivateIPs = true;
$$wgCdnServersNoPurge = ['10.192.0.0/10'];
PHP
rm -rf /var/www/data/install
fi
# The image's html folder is sticky and www-data's, where Linux lets www-data follow only a
# link of its own.
ln -sf /var/www/data/LocalSettings.php LocalSettings.php
chown -h www-data:www-data LocalSettings.php
php maintenance/run.php update --quick
printf 'upload_max_filesize = 100M\npost_max_size = 100M\n' > /usr/local/etc/php/conf.d/uploads.ini
# The web installer is never needed here, and it would greet a stranger: the wiki is
# installed above, and updated at every start.
echo 'RedirectMatch 404 ^/mw-config' > /etc/apache2/conf-enabled/no-installer.conf
chown -R www-data:www-data /var/www/data /var/www/html/images
exec apache2-foreground
volumes:
- data:/var/www/data
- images:/var/www/html/images
healthcheck:
test: ["CMD", "curl", "-fsS", "-o", "/dev/null", "http://127.0.0.1/api.php"]
interval: 10s
timeout: 5s
retries: 30
start_period: 120s
volumes:
data:
images:
More in Notes and wikis
- MemosShort Markdown notes on a private timeline
- HedgeDocMarkdown notes you write together in real time
- Obsidian LiveSyncA CouchDB server that syncs your Obsidian vaults with Self-hosted LiveSync
- BookStackA wiki organised as shelves, books, chapters and pages
- DocmostA collaborative wiki and docs, with spaces, real-time editing and diagrams
- EtherpadDocuments edited together in real time: each author in their own colour, with chat, history and plugins