How to Install MediaWiki on CentOS 7

MediaWiki is a free and open-source wiki application. It runs on many websites, including Wikipedia, Wiktionary and Wikimedia Commons. It is written in the PHP programming language and uses a backend database.

Pre-requisites

MediaWiki depends on a few prerequisites such as Apache (httpd), PHP, MariaDB/mySQL which we'll need to install first,

yum install httpd php php-mysql php-gd mariadb-server php-xml php-intl mysql

output:

[root@vps ~]# yum install httpd php php-mysql php-gd mariadb-server php-xml php-intl mysql
Loaded plugins: fastestmirror, langpacks
base                                                     | 3.6 kB     00:00     
extras                                                   | 3.4 kB     00:00     
updates                                                  | 3.4 kB     00:00     
(1/4): base/7/x86_64/group_gz                              | 166 kB   00:00     
(2/4): extras/7/x86_64/primary_db                          | 156 kB   00:00     
(3/4): updates/7/x86_64/primary_db                         | 1.3 MB   00:00     

Starting the Web Server

Let's start the Apache (httpd) web server and enable it to start automatically on system boot,

systemctl restart httpd.service ; systemctl enable httpd.service

output:

[root@vps ~]# systemctl restart httpd.service ; systemctl enable httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

Starting Database Service

Next, Start the MariaDB database and enable it to start automatically on system boot as well,

systemctl restart mariadb.service ; systemctl enable mariadb.service

output:

[root@vps ~]# systemctl start mariadb.service ;systemctl enable mariadb.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

Create Database

Now lets create a database for MediaWiki, first login to MySQL/MariaDB,

mysql -u root -p

output:

[root@vps ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.60-MariaDB MariaDB Server

Create the database, here we use the name "mediawiki_db" for our database,

CREATE DATABASE mediawiki_db;

output:

MariaDB [(none)]> CREATE DATABASE mediawiki_db;
Query OK, 1 row affected (0.00 sec)

Now, create a user named "wiki_user" with an unique passsword to access the database created above,

Change P@ssWord@123# to something more secure/unqiue when using it for your database password.

GRANT ALL PRIVILEGES ON mediawiki_db.* TO 'wiki_user'@'localhost' IDENTIFIED BY 'P@ssWord@123#' WITH GRANT OPTION;

output:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON mediawiki_db.* TO 'wiki_user'@'localhost' IDENTIFIED BY 'P@ssWord@123#' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

Last but not least, run the command below to enable the privileges setup above,

FLUSH PRIVILEGES;

output:

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

Download MediaWiki release

At the time of this article, MediaWiki 1.24.2 was the latest release, you can download the latest release from MediaWiki when installing it,

Download (via wget) the release archive,

wget https://releases.wikimedia.org/mediawiki/1.24/mediawiki-1.24.2.tar.gz

output:

[root@vps ~]# wget https://releases.wikimedia.org/mediawiki/1.24/mediawiki-1.24.2.tar.gz
--2019-01-12 09:05:48--  https://releases.wikimedia.org/mediawiki/1.24/mediawiki-1.24.2.tar.gz
Resolving releases.wikimedia.org (releases.wikimedia.org)... 91.198.174.192, 2620:0:862:ed1a::1
Connecting to releases.wikimedia.org (releases.wikimedia.org)|91.198.174.192|:443... connected.

Untar the downloaded file using below tar command.

tar -zxpvf mediawiki-1.24.2.tar.gz

output:

[root@vps ~]# tar -zxpvf mediawiki-1.24.2.tar.gz
mediawiki-1.24.2/
mediawiki-1.24.2/opensearch_desc.php5
mediawiki-1.24.2/index.php5
mediawiki-1.24.2/extensions/

Move mediawiki-1.24.2 to its document root (/var/www/html/mediawiki/)

mv mediawiki-1.24.2 /var/www/html/mediawiki

output:

[root@vps ~]# mv mediawiki-1.24.2 /var/www/html/mediawiki
You have mail in /var/spool/mail/root

Setup permissions

chown -R apache:apache /var/www/html/mediawiki/

output:

[root@vps html]# chown -R apache:apache /var/www/html/mediawiki/

chmod 755 /var/www/html/mediawiki/

output:

[root@vps html]# chmod 755 /var/www/html/mediawiki/

output:

[root@vps html]# chmod 755 /var/www/html/mediawiki/

Enable ports 80/443

Allow HTTP/HTTPS ports under firewalld:

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent

output:

[root@vps html]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@vps html]# firewall-cmd --zone=public --add-port=443/tcp --permanent
success

Reload the firewall so the rules applied above are enabled,

firewall-cmd --reload

output:

[root@vps html]# firewall-cmd --reload
success

(Optionally) If your system runs iptables instead of firewalld, allow HTTP/HTTPS ports under iptables:

iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT 
iptables -I INPUT -p tcp -m tcp --dport 443 -j ACCEPT 
service iptables save
service iptables reload

SELinux Rules (Optional)

If Selinux is enabled on your server, then set the following Selinux rules on the MediaWiki folder,

restorecon -FR /var/www/html/mediawiki/

output:

[root@vps html]# restorecon -FR /var/www/html/mediawiki/

Restart the Apache (httpd) service,

systemctl restart httpd

Accessing mediawiki

Now open your web browser and head over to, your MediaWiki installation,

Replace "IP_Address_of_System" with the actual IP of your system/server,

http://IP_Address_of_System/mediawiki

CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!

1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month

Available Locations: LAX | MIA | ATL | FRA | AMS