How to install MediaWiki with Apache on Ubuntu 24.04

This article provides a guide to installing MediaWiki with Apache on Ubuntu 24.04. MediaWiki, known for facilitating collaborative content creation and management, pairs well with the widely supported Apache web server. The installation process involves setting up Apache, installing the MariaDB database server, adding PHP support, and configuring a secure environment for MediaWiki.

This article explains how to install MediaWiki with Apache on Ubuntu 24.04.

MediaWiki, a popular open-source wiki application, fosters a collaborative environment where users can create and manage content. By installing MediaWiki with Apache on Ubuntu, you’re not just setting up a powerful platform for building internal documentation, knowledge bases, and collaborative websites but also encouraging active participation and engagement.

Apache, a widely used web server, is a perfect match for MediaWiki and is fully supported on Ubuntu, making it an excellent choice for hosting MediaWiki. This collaborative setup of MediaWiki with Apache on Ubuntu allows you to create a reliable and flexible environment for hosting your wiki content.

The steps below walk you through installing MediaWiki with Apache support on Ubuntu 24.04.

Install Apache HTTP server on Ubuntu Linux

MediaWiki requires a web server. This post will install and use the Apache web server to run MediaWiki.

To do that, open the Ubuntu terminal and run the commands below to install the Apache web server.

sudo apt update
sudo apt install apache2

Once Apache is installed, the commands below can start, stop, and enable the Apache web server to start automatically when your server boots up.

sudo systemctl stop apache2
sudo systemctl start apache2
sudo systemctl enable apache2

You can test that the Apache web server is running by opening your web browser and browsing to the server’s localhost or IP address.

http://localhost

When you see the Apache2 Default Page, it means the Apache HTTP server is successfully installed.

Additional help on installing Apache on Ubuntu is in the link below.

How to install Apache on Ubuntu

Install MariaDB database server on Ubuntu Linux

The next component that is required to run MediaWiki is a database server. This post will install and use the MariaDB database server to run MediaWiki.

To install and use the MariaDB database server, use the instructions below.

Open the Ubuntu terminal and run the commands below to install the MariaDB database server.

sudo apt update
sudo apt install mariadb-server

Once the MariaDB database server is installed, use the commands below to stop, start, and enable the MariaDB server to start automatically when the server boots.

sudo systemctl stop mariadb
sudo systemctl start mariadb
sudo systemctl enable mariadb

Run the following commands to validate and test if the MariaDB database server is installed successfully.

sudo mariadb

Once you run the commands above, it will log you onto the MariaDB console and display a message similar to the one below.

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 32
Server version: 10.11.2-MariaDB-1 Ubuntu 23.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

The message tells you that the server is installed successfully.

Additional help on installing MariaDB.

Create a MediaWiki database

Upon successfully installing the MariaDB database server, create a blank database on the server specifically for the MediaWiki application.

As part of the setup, we will create a database named ‘mediawikidb‘ and a corresponding user account called ‘mediawikidbuser.’

Finally, we’ll grant the mediawikidbuser full access to the mediawikidb database.

All the database steps above can be done using the commands below:

But first, log on to the MariaDB database server:

sudo mariadb

Then run the commands below to complete the steps:

CREATE DATABASE mediawikidb CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER mediawikidbuser@localhost IDENTIFIED BY 'type_your_password_here';
GRANT ALL ON mediawikidb.* TO mediawikidbuser@localhost WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit

Ensure to replace ‘type_your_password_here ‘with your password.

Install PHP on Ubuntu Linux

The last component you will need to run MediaWiki is PHP. The MediaWiki application is PHP-based and supports the latest versions of PHP.

Run the commands below to install PHP.

sudo apt install php libapache2-mod-php php-intl php-mysql php-curl php-cli php-zip php-xml php-gd php-common php-mbstring php-xmlrpc php-json php-sqlite3 php-soap php-zip

Additional help on installing PHP

How to install PHP on Ubuntu Linux

Download MediaWiki files

Let’s begin the straightforward process of downloading and configuring the MediaWiki files on Ubuntu Linux.

MediaWiki download page

Always check the download page for the latest release. Replace the download link below with the current so you have the latest version.

First, navigate to the /tmp/ directory and download MediaWiki files. After unzipping the file, move the content into the MediaWiki folder in the Apache root directory.

The final step is to change the permissions. This will allow the Apache web server to safely interact with the files, ensuring a secure environment for your MediaWiki installation.

cd /tmp/
curl -O https://releases.wikimedia.org/mediawiki/1.41/mediawiki-1.41.1.tar.gz
tar -xvzf mediawiki-*.tar.gz
sudo cp -rf mediawiki-*/ /var/www/mediawiki
sudo chown -R www-data:www-data /var/www/mediawiki/

Once all the steps are done, configure the Apache webserver to serve the MediaWiki content.

Run the commands below to create an Apache virtual host file for MediaWiki.

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

Then, copy and paste the content block below into the Apache server block.

<VirtualHost *:80>
ServerName mediawiki.example.com
ServerAlias www.mediawiki.example.com
ServerAdmin admin@example.com
DocumentRoot /var/www/mediawiki

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

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Save the file.

Then, run the commands below to enable the virtual host and restart the Apache server.

sudo a2ensite mediawiki.conf
sudo a2enmod rewrite
sudo systemctl restart apache2

Setup Let’s Encrypt SSL/TLS for MediaWiki

You may want to install an SSL/TLS certificate to secure your MediaWiki site. Secure your MediaWiki installation with HTTPS from Let’s Encrypt.

Please read the post below for additional resources on installing and creating Let’s Encrypt SSL certificates for Apache.

How to set up Let’s Encrypt SSL certificate for Apache on Ubuntu Linux

Once you have restarted the Apache web server, open your browser and browse to the server hostname or IP address defined in the Apache server block.

http://mediawiki.example.com

A MediaWiki installation wizard page should appear. Click the ‘Please set up the wiki first’ link and continue.

Next, select the installation language and continue.

Type the database name, account name, and password on the next screen and click continue.

Next, enter your Wiki name, create an administrator account, and continue.

Next, click Continue to begin the installation.

Your MediaWiki site should be set up but not ready to use. Follow the instructions below to complete the setup.

The installer has generated a LocalSettings.php file. It contains all your configuration. You will need to download it and put it in the base of your wiki installation (the same directory as index.php). The download should have started automatically. If the download was not offered, or if you cancelled it, you can restart the download by clicking the link below: Download LocalSettings.php. Note: If you do not do this now, this generated configuration file will not be available later if you exit the installation without downloading it. When that has been done, you can enter your wiki.

Copy the ‘LocalSettings.php’ file into the root directory where Mediawiki files are stored.

sudo cp ~/Downloads/LocalSettings.php /var/www/mediawiki

Your Wiki site should be ready to use.

That should do it!

Conclusion:

  • When installed with Apache on Ubuntu 24.04, MediaWiki creates an environment conducive to fostering collaboration and managing content effectively.
  • The collaborative setup of MediaWiki with Apache on Ubuntu establishes a reliable and flexible environment for hosting wiki content, such as internal documentation, knowledge bases, and collaborative websites.
  • Following the steps, including installing Apache, MariaDB, and PHP and configuring Let’s Encrypt SSL/TLS, you can successfully set up a MediaWiki site with secure HTTPS access.
  • With the comprehensive guidance provided here, you can confidently create a MediaWiki database, download MediaWiki files, configure the Apache server to serve the MediaWiki content, and complete the setup using the installation wizard.
  • This post has illustrated how to seamlessly set up a MediaWiki site on Ubuntu with Apache support, providing an invaluable resource for those seeking to cultivate interactive and information-rich platforms.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *