MediaWiki is an open-source wiki software written in PHP and MySQL. It is scalable and extensible wiki software-powered sites like Wikipedia and Wikimedia. MediaWiki can be used as a collaboration and documentation platform. It allows you to organize documentation and make it public for everyone. It supports multilingual and offers customization for different aspects, from theme/skins, plugins, and editors.

This guide will show you how to install MediaWiki software on Ubuntu 24.04 server. You will install MediaWiki with the LAMP Stack (Linux, Apache, MySQL/MariaDB, and PHP), then secure it with HTTPS through Certbot and Letsencrypt.

Prerequisites

Before you begin, make sure you have the following:

  • An Ubuntu 24.04 server.
  • A non-root user with administrator privileges.
  • A domain name pointed to a server IP address.

Installing Dependencies

To install MediaWiki, you must ensure that dependencies are installed on your system. Currently, the stable version of MediaWiki 1.41 requires PHP 8.1-83. In this section, you will install Apache, MariaDB server, PHP 8.3, and ImageMagick as dependencies for MediaWiki.

First of all, run the following command to update your Ubuntu repository.

sudo apt update

Now, install dependencies for MediaWiki using the following command. Enter Y to confirm the process. With this, you will install the LAMP Stack (Apache, MySQL/MariaDB, and PHP) and ImageMagick packages.

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 dependencies" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/2-install-deps.png665ca30b56b31.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="366" loading="lazy" src="data:image/svg xml,” width=”750″>

After the installation is finished, check the status of the apache2 service with the command below. You will see the Apache web server is running and enabled.

sudo systemctl is-enabled apache2

sudo systemctl status apache2

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

Check the mariadb service with the following command. You can see in the following that the MariaDB server is running and enabled.

sudo systemctl is-enabled mariadb

sudo systemctl status mariadb

<img alt="check mariadb" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/4-check-mariadb.png665ca30bae252.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="248" loading="lazy" src="data:image/svg xml,” width=”750″>

Lastly, check the PHP version using the following command. You will see PHP 8.3 installed on your system.

sudo php -v

<img alt="check php version" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/5-check-php.png665ca30bd2459.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="167" loading="lazy" src="data:image/svg xml,” width=”677″>

Setting up UFW

Add and enable the Apache Full profile on UFW with the following:

sudo ufw allow “Apache Full”

Now verify enabled rules in UFW with the ufw status command below. The Apache Full profile opens ports for both HTTP and HTTPS protocols.

sudo ufw status

<img alt="setup ufw" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/6-setup-ufw.png665ca30beb35f.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="318" loading="lazy" src="data:image/svg xml,” width=”553″>

Configuring PHP

After you have installed dependencies, you will set up PHP by editing the default configuration file /etc/php/8.3/apache2/php.ini.

Run the following nano command to open the PHP config file /etc/php/8.3/apache2/php.ini.

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

Uncomment and change the default PHP configuration with the following. Make sure to adjust both the memory_limit and date.timezone options as needed.

date.timezone = Europe/Amsterdam

upload_max_filesize = 80M

memory_limit = 512M

max_execution_time = 360

Save and exit the file when finished.

Now run the command below to restart the Apache web server and apply your PHP configuration.

sudo systemctl restart apache2

Configuring MariaDB server

Now that PHP is configured, you will secure the MariaDB server and create a new database and user for MediaWiki. You will secure MariaDB with the mariadb-secure-installation utility, then create a new database and user through the mariadb client.

Secure your MariaDB server installation with the mariadb-secure-installation command below.

sudo mariadb-secure-installation

Now you will be asked with following MariaDB server configurations:

  • 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 MariaDB is secured, log in to the MariaDB server with the following – Enter your root password when prompted.

sudo mariadb -u root -p

Next, run the following queries to create a new 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 database details with your information.

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" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/7-create-database.png665ca30c1a2da.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="312" loading="lazy" src="data:image/svg xml,” width=”750″>

Now run the query below to check privileges for user mediawiki. Below you can see user mediawiki can access the database mediawikidb.

SHOW GRANTS FOR mediawiki@localhost;

Lastly, type quit to exit from the MariaDB server.

<img alt="check user privileges" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/8-check-user-privileges.png665ca30c3ed27.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="312" loading="lazy" src="data:image/svg xml,” width=”687″>

In this section, you will download MediaWiki 1.41 source code and set up the installation directory for MediaWiki.

Go to the /var/www directory and download the MediaWiki source code with the curl Command below. Make sure to visit the MediaWiki download page to get the latest version.

cd /var/www/

curl -O https://releases.wikimedia.org/mediawiki/1.41/mediawiki-1.41.1.tar.gz

After downloading, extract the MediaWiki source code and rename the directory to mediawiki. With this, your document root directory for MediaWiki should be available in the /var/www/mediawiki directory.

tar -xvzf mediawiki-.tar.gz

mv mediawiki-
/ mediawiki/

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

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

sudo chmod 755 /var/www/mediawiki

Setting up Apache virtual host

Now that you’ve downloaded the MediaWiki source code, the next step will be creating a new Apache virtual host file for running MediaWiki. Make sure that you have a domain name pointed to your MediaWiki server.

First, run the following command to enable the rewrite module on the Apache web server.

sudo a2enmod rewrite

<img alt="enable rewrite" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/9-enable-mod-rewrite.png665ca30c720d7.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="142" loading="lazy" src="data:image/svg xml,” width=”558″>

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

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

Enter the following configuration and make sure to change the ServerName option with your domain name.

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 and close the file when you’re finished.

Next, run the command below to activate the virtual host file mediawiki.conf and verify your Apache syntax. If you have proper Apache syntax, you will get an output Syntax is OK.

sudo a2ensite mediawiki.conf

sudo apachectl configtest

Lastly, run the command below to restart Apache and apply your changes. With this, your MediaWiki installation should be ready.

sudo systemctl restart apache2

<img alt="setup vhost" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/10-setup-vhost.png665ca30ca771e.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="321" loading="lazy" src="data:image/svg xml,” width=”750″>

In this guide, you will secure MediaWiki with HTTPS. If you’re using public domain, you can use free SSL certificates from Letsencrypt and set up HTTPS automatically. You can generate SSL certificates and set up HTTPS manually for local domain users.

Install the certbot and python3-certbot-apache packages with the following command. Input Y to confirm the installation.

sudo apt install certbot python3-certbot-apache

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

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

You will see SSL/TLS certificates in the /etc/letsencrypt/live/domain.com directory. Your MediaWiki installation should automatically secured with HTTPS.

Installing MediaWiki

Open your web browser and visit your MediaWiki domain name such as http://wiki.hwdomain.io. Click Setup the wiki link to start the installation.

<img alt="setup wiki" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/11-setup-wiki.png665ca30ccbf41.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="353" loading="lazy" src="data:image/svg xml,” width=”518″>

Select your language for MediaWiki and click Continue.

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

Click Continue to accept the MediaWiki terms.

<img alt="accept terms" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/13-accept-license.png665ca30d18df5.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="559" loading="lazy" src="data:image/svg xml,” width=”750″>

Input your MariaDB database details and click Continue.

<img alt="setup database" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/14-database-setup.png665ca30d51470.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="569" loading="lazy" src="data:image/svg xml,” width=”750″>

For the database settings, leave this as default and click Continue.

<img alt="database setting" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/15-same-database-for-installation.png665ca30d9b991.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="397" loading="lazy" src="data:image/svg xml,” width=”750″>

Now input your wiki title and create a new admin user and password for your MediaWiki installation. Then, click Continue again.

<img alt="setup wiki name and user" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/16-setup-wiki-user.png665ca30db656a.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="576" loading="lazy" src="data:image/svg xml,” width=”750″>

On the MediaWiki additional options, go to the Skins section and select your default skin/theme. In this example, we’ll be using MinervaNeue.

<img alt="default theme" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/17-select-default-skin.png665ca30de7850.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="206" loading="lazy" src="data:image/svg xml,” width=”750″>

Scroll down, leave other settings (or change them as needed), then click Continue.

<img alt="additional settings" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/18-options-continue.png665ca30e182ab.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="557" loading="lazy" src="data:image/svg xml,” width=”750″>

Click Continue to confirm the installation.

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

After the installation is complete, click Continue again.

<img alt="installation done" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/20-installation-done.png665ca30ebba2b.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="437" loading="lazy" src="data:image/svg xml,” width=”750″>

Now the file LocalSettings.php will be downloaded automatically to your local machine. Upload that file or create the LocalSettings.php file with the same content as you have.

<img alt="LocalSettings.php" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/21-localsettings.png665ca30f2c61d.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="491" loading="lazy" src="data:image/svg xml,” width=”750″>

In the LocalSettings.php file, change the default option $wgDefaultSkin to minerva.

$wgDefaultSkin = “minerva”;

Now visit your MediaWiki home page and you can see below the home page of the MinervaNeue theme.

<img alt="homepage" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/21-home-minerva.png665ca30f4ce5b.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="478" loading="lazy" src="data:image/svg xml,” width=”750″>

You can now click the login button at the top-right, then input your admin user and password.

<img alt="login" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/06/echo/21-login.png665ca30f7704d.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="478" loading="lazy" src="data:image/svg xml,” width=”417″>

Conclusion

Congratulations! You have completed the installation of MediaWiki on the Ubuntu 24.04 server. You have MediaWiki running with the LAMP Stack (Linux, Apache, MySQL/MariaDB, and PHP) and secured with HTTPS through certbot And Letsencrypt.