Setting Up MediaWiki with Nginx on Ubuntu 22.04

By Chandrashekhar Fakirpure

Updated on May 20, 2024

In this tutorial, we'll discuss about setting up MediaWiki with Nginx on Ubuntu 22.04. PostgreSQL for database and securing with Let's Encrypt. 

MediaWiki is a powerful, open-source wiki software used by organizations worldwide to create collaborative documentation websites. This guide will walk you through the process of installing MediaWiki on an Ubuntu server, using Nginx as the web server and PostgreSQL as the database management system.


Before starting, ensure you have:

  • A running Ubuntu dedicated server or KVM VPS (22.04 or later).
  • Root or sudo user privileges.
  • Basic knowledge of the command line.

Step 1: Update Your System

First, update your package list and upgrade the existing packages:

sudo apt update
sudo apt upgrade -y

Step 2: Install Nginx

Nginx is a high-performance web server that will serve your MediaWiki site.

sudo apt install nginx -y

Step 3: Install and Configure PostgreSQL

PostgreSQL is a powerful, open-source relational database system.

sudo apt install postgresql postgresql-contrib -y

Configure PostgreSQL

Switch to the PostgreSQL user:

sudo -i -u postgres

Create a new PostgreSQL user for MediaWiki:

createuser --interactive --pwprompt
# Enter name of role to add: mediawikiuser
# Enter password for new role: (Choose a strong password)
# Enter it again: (Choose a strong password)
# Shall the new role be a superuser? (y/n) n
# Shall the new role be allowed to create databases? (y/n) y
# Shall the new role be allowed to create more new roles? (y/n) n

Create a new PostgreSQL database for MediaWiki:

createdb -O mediawikiuser mediawikidb

Exit the PostgreSQL prompt:


Step 4: Install PHP and Required Extensions

MediaWiki is written in PHP, so you'll need PHP and its extensions.

sudo apt install php-fpm php-pgsql php-intl php-gd php-xml php-mbstring -y

Step 5: Download and Install MediaWiki

Download the latest version of MediaWiki. Visit official website for latest version:

cd /var/www
sudo wget

Extract the downloaded archive:

sudo tar -xvzf mediawiki-1.41.1.tar.gz
sudo mv mediawiki-1.41.1 mediawiki

Set the correct permissions:

sudo chown -R www-data:www-data /var/www/mediawiki
sudo chmod -R 755 /var/www/mediawiki

Step 6: Configure Nginx

Create a new Nginx configuration file for MediaWiki:

sudo nano /etc/nginx/sites-available/

Note: Replace with your domain name.

Add the following configuration:

server {
    listen 80;

    root /var/www/mediawiki;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
        try_files $uri /index.php;

Note: Replace with your domain name.

Enable the new site and restart Nginx:

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/
sudo systemctl restart nginx

Step 7: Installing SSL Certificate

For added security, consider configuring HTTPS for your Grafana instance. You'll need an SSL certificate for your domain. You can obtain a free SSL certificate from Let's Encrypt using Certbot.

sudo apt install certbot python3-certbot-nginx

Then run the following command to obtain and install the SSL certificate:

sudo certbot --nginx -d

Note: Replace with your domain name.

Follow the prompts to configure HTTPS with Certbot.

Step 8: Complete the Installation via Web Browser 

Open your web browser and navigate to

Follow the on-screen instructions to configure your MediaWiki installation:

  • Select your language and click "Continue".
  • Ensure the environment has the necessary PHP extensions and click "Continue".
  • Enter the database settings:
  • Database type: PostgreSQL
  • Database host: localhost
  • Database name: mediawikidb
  • Database username: mediawikiuser
  • Database password: (the password you created earlier)
  • Click "Continue" and complete the setup by following the remaining steps.

After the setup is complete, download the LocalSettings.php file and upload it to your MediaWiki directory:

sudo mv /path/to/LocalSettings.php /var/www/mediawiki/
sudo chown www-data:www-data /var/www/mediawiki/LocalSettings.php


We have seen setting up MediaWiki with Nginx on Ubuntu 22.04. You now have a fully functional MediaWiki installation running on Ubuntu with Nginx and PostgreSQL. MediaWiki's extensive documentation and active community will be invaluable as you explore its capabilities and customize your wiki to suit your needs. Happy documenting!