MediaWiki is the software behind Wikipedia: proven at enormous scale, with powerful templates, categories, revision history and a huge ecosystem of extensions. It’s an excellent choice for public knowledge bases, community wikis, game and fan wikis, and internal documentation that benefits from wiki markup and structure.
Prefer a simpler or more modern editor? See Wiki.js, BookStack and Outline.
Requirements
- A VPS with 1–2 vCPU and 2 GB RAM for a small wiki.
- Nginx, PHP 8.1+ (check your MediaWiki version’s requirements) with PHP-FPM, and MariaDB or MySQL.
- A domain, e.g.
wiki.example.com.
1. Install the stack
sudo apt update
sudo apt install nginx mariadb-server php-fpm php-mysql php-xml php-mbstring php-intl php-gd php-curl php-apcu imagemagick unzip
See Nginx with PHP-FPM and install MySQL/MariaDB.
2. Create the database
sudo mariadb
CREATE DATABASE wikidb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wikiuser'@'localhost' IDENTIFIED BY 'a-strong-password';
GRANT ALL PRIVILEGES ON wikidb.* TO 'wikiuser'@'localhost';
FLUSH PRIVILEGES;
3. Download MediaWiki
Get the current LTS release from mediawiki.org:
cd /tmp
wget https://releases.wikimedia.org/mediawiki/1.43/mediawiki-1.43.0.tar.gz
tar xzf mediawiki-1.43.0.tar.gz
sudo mv mediawiki-1.43.0 /var/www/wiki
sudo chown -R www-data:www-data /var/www/wiki/images /var/www/wiki/cache
(Use the current version number.)
4. Nginx with short URLs
Pretty URLs like /wiki/Main_Page instead of /index.php?title=Main_Page:
server {
server_name wiki.example.com;
root /var/www/wiki;
index index.php;
client_max_body_size 50M;
location / { try_files $uri $uri/ @rewrite; }
location @rewrite { rewrite ^/wiki/(.*)$ /index.php?title=$1&$args last; }
location = /wiki { return 301 /wiki/Main_Page; }
location ^~ /wiki/ { try_files $uri @rewrite; }
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
location ^~ /images/ { location ~ \.php$ { deny all; } } # never execute uploads
location ^~ /cache/ { deny all; }
location ~ /\.ht { deny all; }
}
Reload Nginx, and add HTTPS with Certbot. See Let’s Encrypt and Nginx try_files.
5. Run the web installer
Open https://wiki.example.com/mw-config/, and follow the steps: database settings, wiki name, the admin account, user rights profile (open, account creation required, or private wiki), and extensions to enable.
At the end, download LocalSettings.php and put it in /var/www/wiki/:
sudo mv ~/LocalSettings.php /var/www/wiki/
sudo chown www-data:www-data /var/www/wiki/LocalSettings.php && sudo chmod 640 /var/www/wiki/LocalSettings.php
Add the short URL settings to LocalSettings.php:
$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true;
Common LocalSettings.php settings
$wgEnableUploads = true; // allow file uploads
$wgFileExtensions[] = 'pdf';
$wgMainCacheType = CACHE_ACCEL; // APCu object cache
$wgEmergencyContact = '[email protected]';
$wgEnableEmail = true; // configure $wgSMTP for reliable mail
// private wiki: only logged-in users can read and edit
$wgGroupPermissions['*']['read'] = false;
$wgGroupPermissions['*']['edit'] = false;
$wgGroupPermissions['*']['createaccount'] = false;
For public wikis, protect against spam: ConfirmEdit (CAPTCHA, or QuestyCaptcha), AbuseFilter, and email confirmation before editing.
Extensions
Install extensions by downloading them into extensions/, then adding wfLoadExtension( 'Name' ); to LocalSettings.php. Popular ones: VisualEditor (WYSIWYG, bundled), SyntaxHighlight, ParserFunctions, Cite, CategoryTree, TemplateData and PluggableAuth/OpenID Connect for SSO.
Background jobs
MediaWiki runs maintenance jobs (link updates, template changes) on page requests by default. On busy wikis, run them from cron instead:
$wgJobRunRate = 0;
*/5 * * * * www-data php /var/www/wiki/maintenance/run.php runJobs --maxtime=280 > /dev/null
(Older versions use maintenance/runJobs.php.) See crontab.
Backups
mysqldump --single-transaction wikidb | gzip > /backups/wikidb-$(date +%F).sql.gz
tar -czf /backups/wiki-files-$(date +%F).tar.gz -C /var/www/wiki LocalSettings.php images extensions
See mysqldump and backup strategy.
Upgrades
Download the new version, copy LocalSettings.php, images/ and custom extensions into it, then run:
php maintenance/run.php update # older versions: php maintenance/update.php
Stay on LTS releases for long support, and update extensions to versions matching your MediaWiki release. Back up first.
Quick reference
| Task | Command / file |
|---|---|
| Web installer | /mw-config/ |
| Main config | LocalSettings.php |
| Short URLs | $wgArticlePath = "/wiki/$1"; + Nginx rewrite |
| Enable extension | wfLoadExtension( 'Name' ); |
| DB upgrade | php maintenance/run.php update |
| Run jobs | php maintenance/run.php runJobs |
Related: PHP-FPM tuning and DokuWiki.