Media Wiki Installation

From NovaOrdis Knowledge Base
Jump to: navigation, search




The following procedure assumes the installation is performed on RHEL 7. It the future details for other OSes might be added.

Install or Update Apache httpd

httpd Installation

Install or Upate PHP Support

yum install php php-mysql php-gd php-xml


The PHP installation command assumes we are going to use MySQL (or MariaDB). Update accordingly if using a different database.

Install the Database

Perform one of the following:

Configure the Database


Connect to mysql.

Create the wiki user:

CREATE USER 'novaordis_wiki'@'localhost' IDENTIFIED BY 'change-this-password';

Create the wiki database:

CREATE DATABASE novaordis_wiki;  

Grant privileges to the database:

GRANT ALL PRIVILEGES ON novaordis_wiki.* TO 'novaordis_wiki'@'localhost';


SHOW GRANTS FOR 'novaordis_wiki'@'localhost';

Download MediaWiki Binaries

Go to and pick the latest release. At the time of the writing, it was mediawiki-1.26.2.tar.gz.

Download it locally in a staging directory:


Install MediaWiki Binaries

As root, unzip in /var/www:

cd /var/www
gunzip < .../mediawiki-1.26.2.tar.gz | tar xfv -

Link to the binaries directory using the same name as the name of the virtual host that will be serving the content:

ln -s mediawiki-1.26.2

Set the correct ownership:

cd /var/www
chown -R apache:apache mediawiki-1.26.2

SELinux Configuration

Find out if SELinux is enabled: how to find out whether SELinux is enabled.

If yes, set the correct SELinux context for MediaWiki files, as root:

restorecon -FR /var/www/mediawiki-1.26.2/
restorecon -FR /var/www/

Check the result:

ls -lZ /var/www/

The MediaWiki directories should have the "system_u:object_r:httpd_sys_content_t:s0" context:

drwxr-xr-x. apache apache system_u:object_r:httpd_sys_content_t:s0 mediawiki-1.26.2
lrwxrwxrwx. root   root   system_u:object_r:httpd_sys_content_t:s0 -> mediawiki-1.26.2

Allow image upload

cd /var/www/mediawiki-1.26.2
chcon -R -t httpd_sys_script_rw_t ./images

Configure httpd to Serve MediaWiki

We assume httpd is correctly installed and configured to support SSL.

We will server MediaWiki as a secure virtual host and a redirecting non-secure host:


    Redirect /

    DocumentRoot /var/www/
    <Directory "/var/www/">  
        DirectoryIndex index.html index.html.var index.php
    # SSL configuration follows ...


Create the MediaWiki Configuration File

Go to your wiki front page. You should see something like this:


"Setting up the wiki" creates the main configuration file LocalSettings.php, which we will upload manually in the DocumentRoot.

scp .../LocalSettings.php /var/www/mediawiki-1.26.2
chown apache:apache LocalSettings.php
chmod go-rwx LocalSettings.php

Access the site, make sure it works, reboot, access it again.


Allow PDF Uploading

Allowed file upload formats are specified using the $wgFileExtensions configuration directive. Usually this directive is situated in LocalSettings.php in the root of the MediaWiki installation.

$wgFileExtensions[] = 'pdf';

To add more than one format:

$wgFileExtensions = array_merge($wgFileExtensions, array( 'pdf', 'txt', 'mp3' ));

Note that the PDF extension will be added to the built-in list ("png", "gif", "jpg", "jpeg").

Increase the Maximum Size for Uploaded Files

Change the following in php.ini file. To locate the php.ini file, see How to Locate php.ini file. You will need to change both upload_max_filesize and post_max_size, as the lower of the two will be the effective one:

; Maximum allowed size for uploaded files.
upload_max_filesize = 10M


; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
post_max_size = 10M

A httpd server upload is required for the change to become effective. To verify that the change was applied correctly, go to "Upload File" and look for "Maximum file size:".

Install BreadCrumbs

  • Go to and download the latest version.
  • gunzip < ... | tar xfv - the downloaded file in /var/www/mediawiki-1.26.2/extensions. The process will create a "BreadCrumbs" subdirectory,
  • chmod -R apache:apache BreadCrumbs
  • Add the following configuration line at the bottom of /var/www/mediawiki-1.26.2/LocalSettings.php
require_once "$IP/extensions/BreadCrumbs/BreadCrumbs.php";

It should start working without restart.

Additional configuration suggestions available on

Install the Math Extension

cd /var/www/mediawiki-1.26.2/extensions
gunzip < .../Math-REL1_30-e13d2d5.tar.gz | tar xfv -

Modify /var/www/mediawiki-1.26.2/LocalSettings.php:

wfLoadExtension( 'Math' );

Run update.php:

cd /var/www/mediawiki-1.26.2/maintenance
php update.php

At this point the Math extension should be installed, but we also need to set math output modes in LocalSettings.php:

// Set MathML as default rendering option
$wgDefaultUserOptions['math'] = 'mathml';
$wgMathFullRestbaseURL= '';

TODO: did not work.

Set up Backup

The backup mechanism consists of two parts: a backup script run periodically with cron on the MediaWiki host and takes snapshots of the database and the file system, and another script run with cron on the NAS server that pulls the backup files and stores them. We opted to go for this solution and not a NFS filesystem mounted on the MediaWiki server because we wanted to completely isolate the MediaWiki host from the NAS server - NAS knows about the MediaWiki server but the MediaServer wiki does not know anything about the NAS server.

MediaWiki Server Backup Setup

Install the Backup Script

Place in /root/bin on the MediaWiki host.

This is a backup-wiki-locally example.

Create the backup directory and make it only writable and readable by root:

mkdir /root/backups
chmod -R go-rwx /root/backups

Configure the backup script with the correct paths and credentials.

Test the backup script:

cd /tmp

It should create a backup file in /root/backups.

Configure cron to run the Backup Script

Follow cron configuration instructions from here: simple cron job.

This is the crontab file, the backup script will be run every morning at 3:00 AM:

0 3 * * * /root/bin/

Configure the NAS Server to Periodically Pull Backup Files

Setup the Script

As root:

mkdir -p /volume4/backups/bin

and place in /volume4/backups/bin. Make it executable by root.

This is a example.

Build and install bakm in the same /volume4/backups/bin directory.

Also create /volume4/backups/bin/backup_operator_identity-id_rsa and place the corresponding public key into the ~/.ssh/authorized-keys of the account that handles the local backup on the other end.

Setup the Task

This procedure applies to a Synology NAS station, for more details see Synology NAS Procedures - Schedule a Task.

Control Panel -> System -> Task Scheduler -> Create -> User-defined script.

Task: " Backup"

User: root


Run command: /volume4/backups/bin/

If the backup on the target host is scheduled at 3:00 AM, schedule this one at 3:30 AM: Schedule -> Ron on the following days: Daily, Time. First Run time: 3:30, Frequency: once a day. Last run time: 03:30.


Fails to upload images with 'Fatal exception of type "MWException"'

Apache error log shows:

[...] PHP Warning:  failed to mkdir "/var/www/mediawiki-1.26.2/images/lockdir" mode 0777 [...]

This is caused by selinux preventing write on the images directory /var/www/mediawiki/images. Fix: #Allow_image_upload.

For more details, see selinux#Permission_Denied_when_Trying_to_Write_in_a_Directory