Log inSign up

Self-hosting a MediaWiki site

Put Nginx, PHP-FPM and MariaDB on the server, unpack the current MediaWiki LTS release into /var/www/wiki and run maintenance/run.php install to create LocalSettings.php. Add short URLs, a Certbot certificate and restricted account creation, and you have a private or public wiki that you fully control.

Topic: Websites, CMS and shops · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13, Rocky Linux 9, AlmaLinux 9 · Updated 2026-12-03

What do you need before installing MediaWiki?

You need a VPS with a sudo user, a domain such as wiki.example.net pointing at it, and a PHP web stack. MediaWiki is plain PHP with a relational database behind it, so 1 GB of RAM handles a small team wiki and 2 GB leaves headroom for search indexing, image thumbnails and the job queue.

If you have not prepared the server yet, start with the first SSH session and point the DNS records as shown in DNS records. The stack itself is described step by step in the LEMP stack guide; the commands below repeat only the packages MediaWiki needs on top of it.

Pick the release line before you start. MediaWiki publishes a long term support (LTS) branch that receives security fixes for several years, plus shorter-lived releases in between. A wiki that should run quietly for a long time belongs on the LTS line. Check the current numbers on the official download page and note the full version, for example 1.43.x.

Which packages does MediaWiki need?

MediaWiki needs PHP with the intl, mbstring, xml, mysql and gd or imagick extensions, plus APCu for the local object cache.

Ubuntu 24.04, Debian 12 and 13

sudo apt update
sudo apt install -y nginx mariadb-server php-fpm php-mysql php-intl php-mbstring php-xml php-gd php-apcu php-curl imagemagick git unzip
php -v
php -m | grep -E 'intl|mbstring|apcu'

Rocky Linux 9 and AlmaLinux 9

sudo dnf module list php
sudo dnf module reset -y php
sudo dnf module enable -y php:8.2
sudo dnf install -y epel-release
sudo dnf install -y nginx mariadb-server php-fpm php-mysqlnd php-intl php-mbstring php-xml php-gd php-pecl-apcu ImageMagick git unzip
sudo systemctl enable --now nginx mariadb php-fpm

On the RHEL family set user = nginx and group = nginx in /etc/php-fpm.d/www.conf and restart PHP-FPM. Current MediaWiki releases need PHP 8.1 or newer, which all of these systems provide.

How do you create the wiki database?

Run the MariaDB hardening script once, then create a database and an account reserved for the wiki.

sudo mariadb-secure-installation
sudo mariadb -e "CREATE DATABASE wikidb CHARACTER SET binary;"
sudo mariadb -e "CREATE USER 'wikiuser'@'localhost' IDENTIFIED BY 'change-this-secret';"
sudo mariadb -e "GRANT ALL ON wikidb.* TO 'wikiuser'@'localhost';"

The binary character set is what the MediaWiki installer picks by default for MariaDB, and it stores every language without surprises. Generate the password with openssl rand -base64 24 rather than typing one by hand.

How do you download and install MediaWiki?

Fetch the release tarball, unpack it into the web root and run the command line installer as the web server user.

MW_BRANCH=1.43
MW_VER=1.43.5
cd /tmp
curl -LO https://releases.wikimedia.org/mediawiki/$MW_BRANCH/mediawiki-$MW_VER.tar.gz
sudo mkdir -p /var/www/wiki
sudo tar -xzf mediawiki-$MW_VER.tar.gz -C /var/www/wiki --strip-components=1
sudo chown -R www-data:www-data /var/www/wiki

Replace both variables with the numbers from the download page. On Rocky and Alma use nginx:nginx as the owner. Now install from the shell; this creates the tables and writes LocalSettings.php for you.

cd /var/www/wiki
sudo -u www-data php maintenance/run.php install --dbname=wikidb --dbuser=wikiuser --dbpass=change-this-secret --server=https://wiki.example.net --scriptpath="" --lang=en --pass=another-long-admin-secret "Example Wiki" Admin

The last two arguments are the wiki name and the first administrator account. If you prefer a browser wizard, skip this command, open /mw-config/ after the Nginx step and download the generated file at the end.

How do you configure Nginx with short URLs?

Serve the wiki from the web root and map /wiki/Page_name to index.php, which gives clean article addresses.

server {
    listen 80;
    listen [::]:80;
    server_name wiki.example.net;
    root /var/www/wiki;
    index index.php;
    client_max_body_size 32m;

    location / { try_files $uri $uri/ @rewrite; }
    location @rewrite { rewrite ^/wiki/(.*)$ /index.php?title=$1&$args last; }
    location ^~ /maintenance/ { deny all; }
    location ^~ /cache/ { deny all; }
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    }
    location ~* \.(js|css|png|jpg|jpeg|gif|svg|ico|webp)$ { expires 30d; try_files $uri =404; }
}

Save it as /etc/nginx/sites-available/wiki, link it into sites-enabled and adjust the socket path to your PHP version. On Rocky and Alma put the file in /etc/nginx/conf.d/wiki.conf, use include fastcgi_params; with fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; and the socket /run/php-fpm/www.sock. Then add these lines to LocalSettings.php:

$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true;
$wgMainCacheType = CACHE_ACCEL;
sudo nginx -t && sudo systemctl reload nginx

How do you add HTTPS and a firewall?

Open ports 80 and 443, then request a certificate with Certbot as described in the Certbot guide.

# Ubuntu and Debian
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable
# Rocky and Alma
sudo firewall-cmd --permanent --add-service=http --add-service=https
sudo firewall-cmd --reload
sudo certbot --nginx -d wiki.example.net

Because $wgServer was set to the https address during install, every generated link already uses TLS. Confirm with curl -I https://wiki.example.net/wiki/Main_Page, which should return 200.

How do you control who can edit and upload?

Permissions live in LocalSettings.php through the $wgGroupPermissions array. A wiki open to anonymous editing attracts spam within days, so most owners close it.

$wgGroupPermissions['*']['edit'] = false;
$wgGroupPermissions['*']['createaccount'] = false;
$wgGroupPermissions['user']['upload'] = true;
$wgEnableUploads = true;
$wgFileExtensions = [ 'png', 'jpg', 'jpeg', 'gif', 'webp', 'pdf' ];

With account creation disabled, administrators add people from Special:CreateAccount. For a private wiki also set $wgGroupPermissions['*']['read'] = false;. If you enable uploads, make sure the images directory is writable by the PHP user and that ImageMagick is on the path through $wgUseImageMagick = true;.

How does the wiki send email?

Password resets and watchlist notices need outgoing mail, and the dependable route is an authenticated SMTP relay on port 587. Do not plan on direct delivery over port 25: open a support ticket first if you want to send mail straight from the server. The relay setup is in SMTP relay for apps, and MediaWiki reads it from $wgSMTP:

$wgSMTP = [
    'host' => 'tls://smtp.example.net',
    'IDHost' => 'example.net',
    'port' => 587,
    'auth' => true,
    'username' => 'wiki@example.net',
    'password' => 'relay-password'
];

The SMTP option relies on the PEAR Mail package; install it with sudo apt install php-mail php-net-smtp on Debian-based systems.

How do you keep MediaWiki updated and backed up?

Update by unpacking the new release over a copy of the old tree, then running the schema updater.

cd /var/www/wiki
sudo -u www-data php maintenance/run.php update --quick
sudo -u www-data php maintenance/run.php version

Keep LocalSettings.php, the images folder and the extensions and skins you added; everything else comes from the tarball. Back up the database with mariadb-dump --single-transaction wikidb and copy it off the server together with images. The optional daily backups add-on protects the whole disk on top of that. Background jobs run during page views by default; on a busy wiki set $wgJobRunRate = 0; and call maintenance/run.php runJobs from a systemd timer or cron every few minutes.

Plans that fit this guide

Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.

All prices
PlanFits becauseSizeMonthlyOrder from
A1-2a small team or personal wiki1 vCPU, 2 GB RAM, 50 GB NVMe$7.20/mo$43.20 for 6 months
A2-4many editors, uploads and extensions2 vCPU, 4 GB RAM, 100 GB NVMe$14.40/mo$43.20 for 3 months

Questions about MediaWiki on Nginx and MariaDB

Which MediaWiki version should I install?

Choose the current LTS release for a wiki you want to leave running, because it gets security fixes the longest. Newer non-LTS releases bring features sooner but need an upgrade roughly every six months.

Why do I see a blank page after editing LocalSettings.php?

A PHP syntax error in that file stops the whole wiki. Run php -l /var/www/wiki/LocalSettings.php and read /var/log/nginx/error.log to find the line.

Can I use PostgreSQL or SQLite instead of MariaDB?

Yes. The installer supports both. SQLite is fine for a single-user notebook; MariaDB or PostgreSQL scale better once several people edit at once.

How do I install an extension?

Download it into extensions/ matching your MediaWiki branch, add wfLoadExtension( 'Name' ); to LocalSettings.php and run the update script if the extension ships database tables.

How much RAM does a MediaWiki site need?

A small wiki runs on 1 GB. Add RAM when you enable full text search engines, many thumbnails or heavy extensions; see moving to a larger plan when you outgrow the first server.