MediaWiki is an open-source wiki software used by the largest wiki sites such as Wikipedia and Wikimedia. It’s free wiki software that can be used as a collaboration and documentation platform. It’s a powerful, scalable, and feature-rich wiki implementation.

This tutorial will show you how to install MediaWiki with the LAMP Stack (Apache, MariaDB, and PHP) on the Debian 12 server. Furthermore, we’ll also show you how to secure MediaWiki with HTTPS via Certtbot and Letsencrypt.

Prerequisites

Before you start, make sure you have the following:

  • A Debian 12 server.
  • A non-root user with administrator privileges.
  • A domain name pointed to a server IP address.

Installing the LAMP Stack

MediaWiki is an open-source software based on PHP with MySQL/MariaDB as the data store. Currently, the current stable version of MediaWiki (1.41) requires at least PHP 7.3.4 or higher and MariaDB 10.3.0. As for web servers, you can use either Apache or Nginx.

In this section, you will be installing the LAMP Stack (Apache, MariaDB, and PHP) that will be used to run your MediaWiki installation.

First, update your Debian repository with the following command.

sudo apt update

Once the repository is updated, install LAMP Stack dependencies with the command below. Input Y to confirm with the installation.

sudo apt install apache2 mariadb-server imagemagick libapache2-mod-php php php-common php-intl php-xml php-curl php-gd php-mbstring php-mysql php-apcu

<img alt="install deps" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/1-install-deps.png6650a9791ca11.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="193" loading="lazy" src="data:image/svg xml,” width=”750″>

Once the installation is complete, verify the Apache and MariaDB service to ensure both services are running.

Verify the Apache web server with the command below. If you get output enabled, this confirms that Apache is enabled and will start automatically at startup. When running, you will see the output active (running).

sudo systemctl is-enabled apache2

sudo systemctl status apache2

<img alt="verify apache2" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/2-verify-apache.png6650a9793c2b6.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="244" loading="lazy" src="data:image/svg xml,” width=”750″>

Next, verify the MariaDB database server with the command below. The output should be similar, an output enabled confirms that MariaDB is enabled, and active (running) confirms that MariaDB is running.

sudo systemctl is-enabled mariadb

sudo systemctl status mariadb

<img alt="verify mariadb" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/3-verify-mariadb.png6650a9797b93a.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="241" loading="lazy" src="data:image/svg xml,” width=”750″>

Lastly, verify the PHP version and list enabled modules with the command below. You will see the PHP 8.2 installed on your Debian server.

php -v

php -m

<img alt="verify php" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/4-verify-php.png6650a9799bf94.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="356" loading="lazy" src="data:image/svg xml,” width=”607″>

Configuring PHP

After you have installed LAMP Stack, you will configure your PHP installation by editing the php.ini file and changing some default parameters for MediaWiki.

To configure PHP, open the PHP configuration /etc/php/8.2/apache2/php.ini with the following nano editor command.

sudo nano /etc/php/8.2/apache2/php.ini

Change the default configuration with the following and make sure to adjust both date.timezone and memory_limit with your current environment.

date.timezone = Europe/Amsterdam

upload_max_filesize = 80M

memory_limit = 512M

max_execution_time = 360

Save and exit the file.

Now run the command below to restart the Apache service and apply your changes.

sudo systemctl restart apache2

Configuring MariaDB Server

With the PHP configured, the next step is to secure the MariaDB server and create a new database and user for MediaWiki. In this example, you will secure the MariaDB server by utilizing the command line mariadb-secure-installation and create a new database and user via the MariaDB client.

To secure MariaDB server installation, run the mariadb-secure-installation command below.

sudo mariadb-secure-installation

Now input Y to accept or n to reject the new configuration on the MariaDB server:

  • The default MariaDB installation comes without a password. Press ENTER when prompted for the password.
  • Now input Y to set up the MariaDB root password. Then, type the new password for MariaDB and repeat the password.
  • Input Y to remove the anonymous user from your MariaDB installation.
  • Input Y again when prompted to disable the remote login for the MariaDB root user.
  • Input Y to remove the default database test from your MariaDB.
  • Lastly, input Y to reload table privileges and apply new changes.

After you have secured MariaDB server deployment, log in to the MariaDB server using the mariadb command below. Input your MariaDB root password when prompted.

sudo mariadb -u root -p

Now run the following queries to create a new MariaDB database and user for MediaWiki. In this example, you will create a new database mediawikidb, a user mediawiki with the password mediawikipassdb. You can adjust the following with your credentials.

CREATE DATABASE mediawikidb;

CREATE USER mediawiki@localhost IDENTIFIED BY 'mediawikipassdb';

GRANT ALL ON mediawikidb.* TO mediawiki@localhost WITH GRANT OPTION;

FLUSH PRIVILEGES;

<img alt="create database and user" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/5-create-db-user.png6650a979bf9f0.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="221" loading="lazy" src="data:image/svg xml,” width=”750″>

Next, run the following query to verify the privileges of the MariaDB user mediawiki. Make sure that the user mediawiki can access the database mediawikidb.

SHOW GRANTS FOR mediawiki@localhost;

Lastly, type quit to exit from the MariaDB when finished.

<img alt="check user privileges" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/6-check-user-priv.png6650a97a06c3b.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="224" loading="lazy" src="data:image/svg xml,” width=”750″>

Now that the dependencies are installed and configured, you can install MediaWiki. There are multiple versions of MediaWiki: stable, legacy, and LTS. In this case, you will install the latest stable version of MediaWiki 1.41.

Move to the /var/www directory and download the MediaWiki source code via the wget command below. Make sure to visit the MediaWiki download page to get the latest version.

cd /var/www/

wget https://releases.wikimedia.org/mediawiki/1.41/mediawiki-1.41.0.tar.gz

Once downloaded, extract the source code with the command below. Then, rename the extracted directory to mediawiki. So, the DocumentRoot directory for MediaWiki will be at /var/www/mediawiki.

tar -xvzf mediawiki-*.tar.gz

mv mediawiki-*/ mediawiki/

Lastly, change the ownership of the /var/www/mediawiki directory to the user www-data and change the permission to 0755.

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

sudo chmod 755 /var/www/mediawiki

Setting Up Apache Virtual Host

So now you have downloaded MediaWiki source code, you will create a new Apache virtual host file for running MediaWiki in this section. So be sure you are equipped with the domain name pointing to your server IP address. For production, purchase the public domain, or you can also use the local domain name.

Before you start, enable the Apache rewrite module with the command below.

sudo a2enmod rewrite

Now create a new Apache virtual host configuration/etc/apache2/sites-available/mediawiki.conf with the nano editor command below.

sudo nano /etc/apache2/sites-available/mediawiki.conf

Insert the following configuration and make sure to change the ServerName option with your domain name and the path of both access and error logs.

ServerName wiki.hwdomain.io

ServerAdmin [email protected]

DocumentRoot /var/www/mediawiki

ErrorLog /var/log/apache2/wiki.hwdomain.io_error.log

CustomLog /var/log/apache2/wiki.hwdomain.io_access.log combined



Options FollowSymlinks

AllowOverride All

Require all granted

Save the file and exit the editor.

Next, activate the virtual host file mediawiki.conf and verify your Apache syntax with the command below. If you have proper Apache syntax, you will see an output such as Syntax OK.

sudo a2ensite mediawiki.conf

sudo apachectl configtest

Lastly, restart the Apache web server to apply the new virtual host for MediaWiki. Once restarted, your MediaWiki installation should be ready.

sudo systemctl restart apache2

<img alt="setup apache vhost" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/7-setup-apache.png6650a97a22cb4.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="359" loading="lazy" src="data:image/svg xml,” width=”682″>

Now you have created an Apache virtual host configuration for MediaWiki, let’s secure your installation with HTTPS via Certbot and letsencrypt. This only applies if you’re using the public domain, but if you’re using the local domain, you can generate Self-signed certificates and apply the HTTPS manually.

Install Certbot and the Certbot Apache plugin with the command below. Type Y to confirm with the installation.

sudo apt install certbot python3-certbot-apache

Once installation is complete, run the certbot command below to generate SSL/TLS certificates for your MediaWiki domain name. Make sure to change the domain name and email address with your information.

sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp --email [email protected] -d wiki.hwdomain.io

After the process is finished, your certificate will be available in the /etc/letsencrypt/live/domain.com directory, while your virtual host also configured with HTTPS.

Installing MediaWiki

Open your preferred web browser and visit your domain name, such as http://wiki.hwdomain.io/. If everything goes well, you should see the MediaWiki welcome page. Click on the set up the wiki link.

<img alt="setup wiki" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/8-setup-wiki.png6650a97a444ae.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="367" loading="lazy" src="data:image/svg xml,” width=”627″>

Select the default language for your MediaWiki and click Continue.

<img alt="select language" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/9-language.png6650a97a79b48.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="298" loading="lazy" src="data:image/svg xml,” width=”750″>

For the environment checks, make sure your system is met with the MediaWiki requirements. Then, click Continue again.

<img alt="environment check" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/10-environment_checks.png6650a97a980ed.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="313" loading="lazy" src="data:image/svg xml,” width=”750″>

Select the database as MariaDB and input your name, user, and password. Then, click Continue to proceed.

<img alt="db configuration" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/11-db-details.png6650a97ab8174.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="410" loading="lazy" src="data:image/svg xml,” width=”750″>

Next, input your admin username, email, and password for MediaWiki, then click Continue.

<img alt="setup admin" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/13-users.png6650a97af3436.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="427" loading="lazy" src="data:image/svg xml,” width=”750″>

For additional settings, select the default theme that you want to use, then click Continue to proceed with the installation.

<img alt="default settings" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/14-settings.png6650a97b25762.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="399" loading="lazy" src="data:image/svg xml,” width=”750″>

Click Continue to confirm the MediaWiki installation.

<img alt="confirm the installation" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/15-confirm-install.png6650a97b5b55f.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="280" loading="lazy" src="data:image/svg xml,” width=”750″>

<img alt="complete" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/16-complete.png6650a97b852b6.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="323" loading="lazy" src="data:image/svg xml,” width=”750″>

Once the installation is complete, the file LocalSettings.php will automatically downloaded to your local computer and you will see an instruction to upload the file to your MediaWiki installation directory.

<img alt="installation finished" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/17-finished.png6650a97bb384a.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="360" loading="lazy" src="data:image/svg xml,” width=”750″>

Back to your terminal and run the command below to create a new file LocalSettings.php.

sudo -u www-data nano /var/www/mediawiki/LocalSettings.php

Open the file LocalSettings.php you downloaded, and copy and paste the PHP code into your server. Then, save the file and exit.

Return to your web browser and click the link to enter the wiki. You will see the default home page of MediaWiki that you have installed.

<img alt="mediawiki home" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/18-wiki-home.png6650a97be3b0c.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="242" loading="lazy" src="data:image/svg xml,” width=”750″>

Conclusion

Congratulations! You have now successfully installed MediaWiki on Debian 12 server. You have installed MediaWiki with the LAMP Stack (Apache, MariaDB, and PHP) and secured MediaWiki with HTTPS from Letsencrypt.