Tutorial

How to Install MediaWiki on Ubuntu 24.04

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

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

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

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

sudo php -v

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

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;

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.

Downloading MediaWiki

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

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.

<VirtualHost *:80>
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

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

</VirtualHost>

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

Securing MediaWiki with HTTPS

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.

Select your language for MediaWiki and click Continue.

Click Continue to accept the MediaWiki terms.

Input your MariaDB database details and click Continue.

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

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

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

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

Click Continue to confirm the installation.

After the installation is complete, click Continue again.

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.

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.

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

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.

Đăng ký liền tay Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !

Add Comment

Click here to post a comment

Đăng ký liền tay
Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !