How to Install MediaWiki on Ubuntu 20.04

Install MediaWiki on Ubuntu 20.04

In this article, we will have explained the necessary steps to install and configure MediaWiki with LAMP on Ubuntu 20.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Mediawiki is a free and open-source wiki software that allows you to create your own wiki site. It currently runs on many famous websites such as Wikipedia, Wiktionary, and Wikimedia Commons. MediaWiki is written in PHP.

Install MediaWiki on Ubuntu 20.04

Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.

sudo apt update
sudo apt upgrade

Step 2. Install LAMP Stack on Ubuntu.

Drupal is built with PHP. You can host it like you would any other web app is written in PHP. So, you’re going to need to set Ubuntu up as either a LAMP server. If you haven’t done so already, use our traditional LAMP guide to set up Ubuntu to serve PHP before you continue.

Step 3. Install MediaWiki on the Ubuntu system.

Run the commands below to download MediaWiki latest release:

cd /tmp/
wget https://releases.wikimedia.org/mediawiki/1.35/mediawiki-1.35.2.tar.gz

Extract the file downloaded:

tar -xvzf mediawiki-*.tar.gz
rm mediawiki-*.tar.gz
sudo mv mediawiki-* /var/www/html/mediawiki

Then, set the appropriate permissions:

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

Step 4. Creating a Database for MediaWiki.

MediaWiki uses the MySQL database to store all its data. Log in to your MySQL server with the following command and enter your MySQL root password:

mysql -u root -p

Once you’re in the MySQL console, create a new database:

MariaDB [(none)]>CREATE DATABASE mediadb;
MariaDB [(none)]>CREATE USER 'media'@'localhost' IDENTIFIED BY 'your-password';
MariaDB [(none)]>GRANT ALL ON mediadb.* TO 'media'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
MariaDB [(none)]>FLUSH PRIVILEGES;
MariaDB [(none)]>EXIT;

Step 5. Configuring Apache for MediaWiki.

Create a new virtual host configuration file for your MediaWiki website, named your-domain.com.conf:

nano /etc/apache2/sites-available/your_domain.com.conf

And add the following content to the file:

<VirtualHost *:80>
     ServerAdmin admin@your-domain.com
     DocumentRoot /var/www/html/mediawiki
     ServerName your-domain.com
     ServerAlias www.your-domain.com

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

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

To enable the virtual host we have just created, run the following command:

ln -s /etc/apache2/sites-available/your-domain.com.conf /etc/apache2/sites-enabled/your-domain.com.conf

For the new configuration to take effect, restart the Apache service by typing:

sudo a2ensite your_domain.com.conf
sudo a2enmod rewrite 
sudo systemctl restart apache2

Step 6. Secure MediaWiki with Let’s Encrypt SSL.

First, you will need to install the Certbot client to install and manage the Let’s Encrypt SSL. You can install it with the following command:

sudo apt install certbot python3-certbot-apache

Once the Certbot is installed, run the following command to download and install Let’s Encrypt SSL for your website:

certbot --apache -d your_domain.com

Step 7. Accessing the MediaWiki Installation.

Go to https://your_domain.com in your web browser to start the web-based installation script. Click Complete the installation link to start the setup wizard.

Install MediaWiki on Ubuntu 20.04

That’s all you need to do to install MediaWiki on Ubuntu 20.04 LTS Focal Fossa. I hope you find this quick tip helpful. For further reading on MediaWiki Content Management System, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.