How to Install MediaWiki on Debian 12

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

install deps

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

verify apache2

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

verify mariadb

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

verify php

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;

create database and user

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.

check user privileges

Downloading MediaWiki Source Code

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.

<VirtualHost *:80>

ServerName wiki.howtoforge.local

ServerAdmin [email protected]
DocumentRoot /var/www/mediawiki

ErrorLog /var/log/apache2/wiki.howtoforge.local_error.log
CustomLog /var/log/apache2/wiki.howtoforge.local_access.log combined

<Directory /var/www/mediawiki/>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>

</VirtualHost>

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

setup apache vhost

Securing MediaWiki with HTTPS

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.howtoforge.local

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.howtoforge.local/. If everything goes well, you should see the MediaWiki welcome page. Click on the set up the wiki link.

setup wiki

Select the default language for your MediaWiki and click Continue.

select language

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

environment check

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

db configuration

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

setup admin

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

default settings

Click Continue to confirm the MediaWiki installation.

confirm the installation

complete

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.

installation finished

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.

mediawiki home

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.

Share this page:

0 Comment(s)