How to Install MediaWiki on Ubuntu Server
This guide walks through installing MediaWiki on a fresh Ubuntu Server instance, from a bare LAMP stack (Linux, Apache, MariaDB, PHP) through running the web-based installer and securing the site with HTTPS. It assumes a server running Ubuntu Server 24.04 LTS with sudo access, though the same steps apply with minor adjustments on Ubuntu 22.04 LTS or 26.04 LTS.
For background on what MediaWiki is and why an organization might choose it, see "What Is MediaWiki?" This article focuses purely on the installation process itself.
What You'll Need
| Requirement | Detail |
|---|---|
| Server | Ubuntu Server 24.04 LTS (or 22.04 LTS / 26.04 LTS) with sudo or root access |
| PHP | Version 8.2.0 or later (Ubuntu 24.04 ships PHP 8.3 by default in its standard repositories) |
| Database | MariaDB 10.3.0+ or MySQL 5.7.0+ (this guide uses MariaDB) |
| Web server | Apache with mod_rewrite enabled (this guide uses Apache; Nginx is also supported) |
| Domain name | Optional but recommended if you plan to enable HTTPS with a trusted certificate |
| MediaWiki release | Current stable (1.45.x) or long-term-support (1.43.x) tarball from the official download page |
Step 1: Update the Server and Install Apache
Update the package index:
sudo apt update
Upgrade existing packages:
sudo apt upgrade -y
Install Apache:
sudo apt install apache2 -y
Enable and start the Apache service:
sudo systemctl enable apache2 sudo systemctl start apache2
If a firewall is active, allow SSH access:
sudo ufw allow OpenSSH
Allow web traffic:
sudo ufw allow 'Apache Full'
Enable the firewall:
sudo ufw enable
Step 2: Install and Secure MariaDB
Install the MariaDB server package:
sudo apt install mariadb-server -y
Enable and start the service:
sudo systemctl enable mariadb sudo systemctl start mariadb
Run the included security script:
sudo mysql_secure_installation
This script will prompt to set a root database password, remove anonymous users, disable remote root login, and remove the test database. Answer "yes" to each prompt for a production server.
Step 3: Install PHP and Required Extensions
Ubuntu 24.04's default repositories include PHP 8.3, which already meets MediaWiki's PHP 8.2+ requirement, so no third-party PPA is needed in most cases.
sudo apt install php libapache2-mod-php php-mysql php-xml php-mbstring php-intl php-apcu php-curl unzip wget -y
Restart Apache so the PHP module loads:
sudo systemctl restart apache2
Confirm the installed version:
php -v
This should report PHP 8.3.x or later. The php-apcu package provides object caching, and php-curl is required if you plan to install VisualEditor later, since it depends on the Parsoid service.
Step 4: Create the MediaWiki Database and User
Log into the MariaDB shell:
sudo mysql -u root -p
At the MariaDB prompt, create the database:
CREATE DATABASE wikidb CHARACTER SET utf8mb4;
Create a dedicated user for the wiki:
CREATE USER 'wikiuser'@'localhost' IDENTIFIED BY 'ReplaceWithAStrongPassword';
Grant that user access to the new database:
GRANT ALL PRIVILEGES ON wikidb.* TO 'wikiuser'@'localhost';
Apply the changes and exit:
FLUSH PRIVILEGES; EXIT;
Replace the placeholder password with a strong, unique one, and keep a record of the database name, username, and password - the web installer will ask for all three.
Step 5: Download and Extract MediaWiki
Check the official MediaWiki download page for the current version number before running this step, since release numbers change over time. As of this writing, the current stable release is 1.45.3 and the current long-term-support release is 1.43.8.
Move to a temporary directory:
cd /tmp
Download the release archive:
wget https://releases.wikimedia.org/mediawiki/1.45/mediawiki-1.45.3.tar.gz
Extract it:
tar -xzf mediawiki-1.45.3.tar.gz
Move it into the web root:
sudo mv mediawiki-1.45.3 /var/www/html/w
Set ownership to the Apache user:
sudo chown -R www-data:www-data /var/www/html/w
Installing into a subdirectory such as /w rather than directly into the document root is the configuration MediaWiki's own documentation recommends, and it makes setting up clean "/wiki/" short URLs straightforward later.
Step 6: Configure Apache for the Wiki
Create a dedicated Apache site configuration file:
sudo nano /etc/apache2/sites-available/wiki.conf
Add the following content to that file, replacing yourdomain.com with your actual domain or server IP address.
ServerName yourdomain.com DocumentRoot /var/www/html/w |
AllowOverride All Require all granted |
ErrorLog ${APACHE_LOG_DIR}/wiki_error.log
CustomLog ${APACHE_LOG_DIR}/wiki_access.log combined
|
The full block, when assembled in the actual file, is a standard VirtualHost entry on port 80 with a matching Directory block for /var/www/html/w, with the two log lines and the override/permission lines placed inside it as shown above.
Enable the new site:
sudo a2ensite wiki.conf
Enable the rewrite module:
sudo a2enmod rewrite
Disable the default site and reload Apache:
sudo a2dissite 000-default.conf sudo systemctl reload apache2
Step 7: Run the Web-Based Installer
With Apache and the database ready, open a browser and navigate to your server's domain or IP address. MediaWiki's installer will detect the environment and walk through the remaining configuration:
- Select a language for the wiki interface and the installer itself.
- Confirm that environment checks pass (PHP version, required extensions, file permissions).
- Enter a name for the wiki and an email address for the wiki's administrator contact.
- Choose MySQL as the database type (MariaDB uses the same driver) and enter the database name, username, and password created in Step 4.
- Create an administrator account - this will be the first user with full sysop privileges.
- Choose initial settings for user rights (for example, whether anonymous users can edit or only read).
- Optionally select extensions to enable at this stage, such as Cite or ParserFunctions.
- Complete the installation. The installer will generate a
LocalSettings.phpfile.
If the installer cannot write LocalSettings.php directly due to file permissions (the more secure and common outcome on a properly permissioned server), it will instead offer the file for download. Transfer it into the /var/www/html/w/ directory using SFTP, then refresh the wiki's homepage to confirm the installation completed successfully.
Step 8: Set File Permissions
After installation, confirm the uploads directory has appropriate permissions:
sudo chmod 755 /var/www/html/w/images
Confirm ownership of the configuration file:
sudo chown www-data:www-data /var/www/html/w/LocalSettings.php
Step 9: Secure the Site With HTTPS
For any wiki accessible over the public internet, HTTPS is a baseline requirement. If a domain name is already pointed at the server, Certbot can issue and configure a free certificate automatically.
Install Certbot:
sudo apt install certbot python3-certbot-apache -y
Request and apply a certificate:
sudo certbot --apache -d yourdomain.com
Certbot will modify the Apache configuration to redirect HTTP traffic to HTTPS and will handle certificate renewal automatically going forward.
Step 10: Configure Short URLs (Optional)
By default, wiki pages are accessed at URLs like yourdomain.com/w/index.php?title=Page_Name. Many wikis prefer cleaner URLs such as yourdomain.com/wiki/Page_Name. To enable this, add the following lines to the Apache virtual host created in Step 6, one at a time:
RewriteEngine On
RewriteRule ^/wiki/(.*)$ /w/index.php?title=$1
RewriteRule ^/wiki$ /w/index.php
Then update LocalSettings.php with:
$wgScriptPath = "/w";
$wgArticlePath = "/wiki/$1";
Restart Apache after making these changes, and test that both the root wiki page and an individual article load correctly at the new short URL pattern before relying on it.
Best Practices for a New Installation
Run system updates regularly to keep the underlying OS and PHP packages patched. Subscribe to MediaWiki's release announcement mailing list so security releases aren't missed. Take a database export and a file-level backup of the wiki directory before any core, extension, or PHP version upgrade. Disable public account creation or require email confirmation if the wiki is not intended to be fully open to anonymous registration, since this is a common early source of spam accounts. Finally, restrict SSH access (key-based authentication, no direct root login) as a baseline server-hardening step independent of MediaWiki itself.
Common Mistakes and Troubleshooting
| Symptom | Likely Cause | Fix |
|---|---|---|
| Blank white page after installation | PHP error reporting disabled and an unmet extension dependency | Check the Apache error log; confirm all required PHP extensions from Step 3 are installed |
| "Could not connect to database" during installer | Wrong database name, username, or password, or MariaDB not running | Re-check Step 4 credentials; confirm the MariaDB service is active |
| Images fail to upload | Incorrect permissions on the images/ directory |
Re-run the permission command from Step 8 and confirm ownership is www-data
|
| Short URLs return a 404 error | mod_rewrite not enabled, or AllowOverride not set in the virtual host |
Confirm the rewrite module was enabled and that the directory block in Step 6 includes AllowOverride All
|
| Site loads over HTTP but not HTTPS | DNS not yet pointed at the server when Certbot ran, or port 443 blocked by the firewall | Confirm DNS propagation, then re-run the certificate request; check the firewall status |
Frequently Asked Questions
Do I need Nginx instead of Apache?
No. Apache is used in this guide because its configuration is straightforward for short URLs, but MediaWiki runs equally well on Nginx with PHP-FPM. The core installation steps (PHP, database, MediaWiki files, web installer) are the same; only the web server configuration syntax differs.
Can I install MediaWiki on Ubuntu 22.04 LTS instead of 24.04?
Yes. Ubuntu 22.04 LTS's default repositories include an older PHP version, so confirm the installed PHP version meets MediaWiki's 8.2+ requirement, and use the Ondřej Surý PPA to install a newer PHP version if needed.
Should I use the stable release or the long-term-support (LTS) release?
For a production wiki where minimizing upgrade frequency matters more than having the newest features immediately, the LTS branch (currently 1.43.x) is generally the safer choice, since it receives a longer security support window than standard releases.
Is it safe to leave the installer's configuration directory writable after installation?
It's good practice to restrict or remove write access to the installation directory after setup is complete, since an exposed, writable configuration script is an unnecessary attack surface on a production server.
How do I upgrade MediaWiki after this initial installation?
Download the new release, extract it alongside (not over) the existing installation, copy your existing configuration file and uploads directory into the new version's folder, then run the core update maintenance script from the new directory to apply any database schema changes.
Conclusion
Installing MediaWiki on Ubuntu Server is a standard LAMP-stack deployment with a few MediaWiki-specific steps layered on top: creating a dedicated database and user, downloading and extracting the official release into a subdirectory, running the web-based installer, and configuring HTTPS and short URLs afterward. None of these steps are individually difficult, but skipping the planning around file permissions, backups, or update discipline is where most production issues later originate.
If this is being set up for an organization rather than a personal project, and ongoing maintenance, custom branding, or content migration is also needed, that broader scope is covered on SolidWiki's MediaWiki Development Services page.
See Also
- What Is MediaWiki?
- MediaWiki Security Hardening Guide
- MediaWiki Performance Optimisation
- Top MediaWiki Extensions for Business Wikis
- MediaWiki vs Confluence Comparison
References