Table of Contents
In this article, I will take you through the steps to install and setup MediaWiki on Ubuntu 20.04 LTS. MediaWiki is a free and open source software used to power Wikipedia and thousands of other Wikis. Its rich and extensible feature allows it to become one of the best choice for lot of Organization to manage their contents. MediaWiki is localised in more than 350 languages and is very simple to install. It can be installed on almost any kind of hardware and software combination. For now, we will see the steps to install and then setup MediaWiki on Ubuntu 20.04 LTS in great detail in below section. More on MediaWiki documentation.
How to Install and Setup MediaWiki on Ubuntu 20.04 LTS
Also Read: How to Enable root user for SSH Authentication on Ubuntu 20.04 LTS
Step 1: Prerequisites
a) You should have a running Ubuntu 20.04 LTS
Server.
b) You should have sudo
or root
access to run privileged commands.
c) You should have apt
or apt-get
utility installed in your Server.
Step 2: Update Your System
It is very important to keep the server updated using apt update
or apt-get update
command. It will ensure the installation of latest version of all the installed packages which will further reduce the chances of any broken dependency problem.
root@localhost:~# apt-get update
Hit:1 http://in.archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Get:4 https://apt.releases.hashicorp.com focal InRelease [6,117 B]
Get:5 http://ppa.launchpad.net/ansible/ansible/ubuntu focal InRelease [18.0 kB]
Get:6 https://packages.microsoft.com/repos/edge stable InRelease [7,342 B]
Get:7 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:8 http://in.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages [554 kB]
Hit:9 http://ppa.launchpad.net/micahflee/ppa/ubuntu focal InRelease
Get:10 https://apt.releases.hashicorp.com focal/main amd64 Packages [35.3 kB]
Get:11 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [1,303 kB]
Get:12 http://in.archive.ubuntu.com/ubuntu focal-updates/main Translation-en [270 kB]
Get:13 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [279 kB]
Get:14 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 c-n-f Metadata [14.4 kB]
Step 3: Install Tasksel
Since we need to install lamp-server using tasksel utility so we first have to install tasksel utility itself as a prerequisite using apt-get install tasksel -y
command as shown below.
root@localhost:~# apt-get install tasksel -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
tasksel-data
The following NEW packages will be installed:
tasksel tasksel-data
0 upgraded, 2 newly installed, 0 to remove and 7 not upgraded.
Need to get 34.0 kB of archives.
After this operation, 289 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu focal/main amd64 tasksel-data all 3.34ubuntu16 [5,340 B]
Get:2 http://in.archive.ubuntu.com/ubuntu focal/main amd64 tasksel all 3.34ubuntu16 [28.6 kB]
Fetched 34.0 kB in 1s (61.6 kB/s)
Preconfiguring packages ...
Step 4: Install LAMP Server
Instead of installing all the components of LAMP Server individually using apt or apt-get package manager, you can use tasksel to install lamp-server which contains all the LAMP Server components. This can be done by using tasksel install lamp-server
command as shown below.
root@localhost:~# tasksel install lamp-server
Step 5: Check MySQL Service
After LAMP Server installation, you can check MySQL service by using systemctl status mysql
command. It should show in active and running state as you can see below.
root@localhost:~# systemctl status mysql
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2021-11-06 07:45:15 IST; 9min ago
Main PID: 12220 (mysqld)
Status: "Server is operational"
Tasks: 37 (limit: 2314)
Memory: 352.5M
CGroup: /system.slice/mysql.service
└─12220 /usr/sbin/mysqld
Step 6: Create a Database
By default, MySQL Server does not ask for password when you try to login with root user account. So you can login to MySQL server using mysql -u root
command as shown below.
root@localhost:~# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.27-0ubuntu0.20.04.1 (Ubuntu)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
After login to MySQL Server, you need to first create a database to store all the data. Here we are creating a database called mediawiki
using create database mediawiki
query.
mysql> create database mediawiki;
Query OK, 1 row affected (0.05 sec)
Then we need to create a user that will have complete access of mediawiki database. Here we are creating a user called wkuser
and setting his password using create user 'wkuser'@'localhost' identified by 'wiki123'
query.
mysql> create user 'wkuser'@'localhost' identified by 'wiki123';
Query OK, 0 rows affected (0.31 sec)
Next, you need to grant complete access of mediawiki
database to wkuser
using grant all privileges on mediawiki.* to 'wkuser'@'localhost'
query.
mysql> grant all privileges on mediawiki.* to 'wkuser'@'localhost';
Query OK, 0 rows affected (0.00 sec)
Finally, you need to run flush privileges
to update all the changes and then quit the database using exit
.
mysql> flush privileges; Query OK, 0 rows affected (0.30 sec) mysql> exit; Bye
Step 7: Install MediaWiki
In the next step, you need to download and install MediaWiki from Ubuntu Repository using apt-get install mediawiki -y
command as shown below. This will download and install MediaWiki package along with its required dependencies.
root@localhost:~# apt-get install mediawiki -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libonig5 mediawiki-classes php php-apcu php-apcu-bc php-curl php-intl php-mbstring php-wikidiff2 php-xml php7.4 php7.4-curl php7.4-intl php7.4-mbstring
php7.4-xml
Suggested packages:
imagemagick | php-gd memcached clamav php-gd
The following NEW packages will be installed:
libonig5 mediawiki mediawiki-classes php php-apcu php-apcu-bc php-curl php-intl php-mbstring php-wikidiff2 php-xml php7.4 php7.4-curl php7.4-intl
php7.4-mbstring php7.4-xml
0 upgraded, 16 newly installed, 0 to remove and 7 not upgraded.
Need to get 24.1 MB of archives.
After this operation, 137 MB of additional disk space will be used.
Step 8: Setting Up Directory
After successful installation, you need to set up the MediaWiki directory under /var/www/html
path so that it can be used to serve requests sent to the apache web server. For this you need to create a directory called mediawiki
under /var/www/html
using mkdir /var/www/html/mediawiki
command and then copy all the contents from /var/lib/mediawiki
to this directory using cp -R /var/lib/mediawiki/* /var/www/html/mediawiki/
command as shown below.
root@localhost:~# mkdir /var/www/html/mediawiki root@localhost:~# cp -R /var/lib/mediawiki/* /var/www/html/mediawiki/
Step 9: Setting FQDN
Since I don't have any fully qualified domain name yet to use in the apache configuration, so I will first set up my FQDN. This can be easily done by mapping your local IP with your chosen domain name in /etc/hosts
file. For the moment, I am going to use mediawiki.example.com
as my FQDN so I will map my local IP with this FQDN in /etc/hosts
file as shown below. Here my local IP Address is 192.168.29.194. This could be different for you so you need to map it accordingly.
root@localhost:~# nano /etc/hosts 127.0.0.1 localhost 192.168.29.194 mediawiki.example.com # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters
To verify, you can run ping command and check if this FQDN is working fine.
root@localhost:~# ping mediawiki.example.com
PING mediawiki.example.com (192.168.29.194) 56(84) bytes of data.
64 bytes from mediawiki.example.com (192.168.29.194): icmp_seq=1 ttl=64 time=0.028 ms
64 bytes from mediawiki.example.com (192.168.29.194): icmp_seq=2 ttl=64 time=0.017 ms
64 bytes from mediawiki.example.com (192.168.29.194): icmp_seq=3 ttl=64 time=0.027 ms
64 bytes from mediawiki.example.com (192.168.29.194): icmp_seq=4 ttl=64 time=0.057 ms
64 bytes from mediawiki.example.com (192.168.29.194): icmp_seq=5 ttl=64 time=0.031 ms
^C
--- mediawiki.example.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4088ms
rtt min/avg/max/mdev = 0.017/0.032/0.057/0.013 ms
Step 10: Configure Apache Server
Once you have all the prerequisites to set up the Apache configuration, then you need to create Mediawiki configuration (mediawiki.conf) under /etc/apache2/sites-available
path as shown below. In this configuration, we will be providing HTTP Port 80
to Listen all the incoming requests on Port 80. Then providing ServerAdmin as admin@example.com
and ServerName as mediawiki.example.com
. You can set these information as per your local Server details.
root@localhost:~# nano /etc/apache2/sites-available/mediawiki.conf
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/mediawiki/
ServerName mediawiki.example.com
<Directory /var/www/html/mediawiki/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/mediawiki_error
CustomLog /var/log/apache2/mediawiki_access common
</VirtualHost>
Step 11: Reload Apache
After setting up the apache configuration, you need to enable MediaWiki by using a2ensite mediawiki.conf
command as shown below.
root@localhost:~# a2ensite mediawiki.conf
Enabling site mediawiki.
To activate the new configuration, you need to run:
systemctl reload apache2
Then reload apache2 service by using systemctl reload apache2
command.
root@localhost:~# systemctl reload apache2
Step 12: Open MediaWiki
To open MediaWiki default home page, you need to open your favorite browser and provide URL http://mediawiki.example.com
. This should open the MediaWiki page as shown below. Also you can notice that currently it shows LocalSettings.php not found
. So to create this configuration file you need to Click on set up the wiki
link.
Step 13: Setup MediaWiki
It will take you to below Installation page where you need to select your Language and then Click on Continue
.
Next window will perform the Environmental checks and see if the system has also prerequisites installed. Then Click on Continue
.
Here you need to provide MySQL database name that we created earlier along with the user account information. Then Click on Continue
to connect the database.
Once DB is connected, it will ask you to select Storage Engine. By default, InnoDB
will be selected as this is the recommended one. So we will not change anything here and just Click on Continue
to proceed.
Here you need to provide the Project name and administrator account credentials to setup the Project. Then Click on Continue
to set up Project Namespace.
Then in the User rights profile, by default Open wiki will be selected which we will leave as it is and then Click on Continue
. This option allows Wikis to work best when you let as many people edit them as possible.
Finally you will get the install window where you just need to Click on Continue
to start the Installation if everything looks ok.
As soon as you click Continue
, it will start setting up the database, creating tables, populating wiki details on the database tables. Once it is completed, you can click on Continue
to finish the Installation.
Below displayed output shows MediaWiki 1.31.7 has been installed successfully.
At the end of the installation, you will have the LocalSettings.php
file generated which contains all your configuration. You need to download this file and copy it under /etc/mediawiki
path.
root@localhost:~# cp /home/cyberithub/Downloads/LocalSettings.php /etc/mediawiki/
Then again open the URL http://mediawiki.example.com
.