MediaWiKi Installation

Mason Lyu
MischievousBOSS
Published in
5 min readApr 25, 2021

This article describe the manual installation of MediaWiKi on Synology DSM. Of course, we can install MediaWiKi within Package Center, but what if we want to have two or more MediaWiKi sites on single Synology DiskStation?

Photo by Kuma Kum on Unsplash

Prerequisite

MediaWiki requires PHP, database and web server to be installed on system. Check out MediaWiKi Compatibility to find out the eligible software version.

PHP

The latest stable branch of MediaWiki (1.35) runs on any version of PHP 7.3 from 7.3.19 and higher, and any version of PHP 7.4 from 7.4.3 and higher.Before installing MediaWiKi, some of the PHP extensions are suggested to be enabled additionally.

Database

MediaWiki is compatible with a variety of database servers. Using MySQL or MariaDB is recommended. Since MediaWiki 1.34, using Oracle and Microsoft SQL Server are no longer supported.

Web server

MediaWiki is broadly compatible with all major web servers that can invoke a compatible version of PHP. Apache is the most used and tested. Nginx is a good choice as well.

Installation

1. Download the source file from MediaWiKi website.

2. Follow the instruction to install MediaWiKi on system.

3. Download and modify the content of LocalSettings.php.

4. Upload LocalSettings.php to the base directory of the MediaWiki installation.

5. All the changes in LocalSettings.php will be effective immediately without rebooting system.

LocalSetting.php

Email Configuration

Reference: Manual:$wgSMTP

IDHost is a MediaWiki-specific setting used to build the Message-ID email header. If not provided, will default to $wgServer.

$wgSMTP = [
'host' => 'ssl://smtp.gmail.com', // outbox server of the email account
'IDHost' => 'gmail.com',
'port' => 465,
'username' => 'myemail@gmail.com',
'password' => '********', // Application password
'auth' => true
];

Group Permissions

  • Check if anonymous user can create an account
$wgGroupPermissions['*']['createaccount'] = flase;
  • Check if anonymous user can edit the page
$wgGroupPermissions['*']['edit'] = false;
  • Check if anonymous user can read the page
$wgGroupPermissions['*']['read'] = false;
  • Add following lines when using VisualEditor since VisualEditor accesses your pages as an anonymous user. Reference.
if ( $_SERVER['REMOTE_ADDR'] == 'YOUR_SERVER_IP' ) {
$wgGroupPermissions['*']['read'] = true;
$wgGroupPermissions['*']['edit'] = true;
}

Miscellaneous Settings

  • MultimediaViewer extension
wfLoadExtension( 'MultimediaViewer' );
$wgDefaultUserOptions['multimediaviewer-enable'] = 1;
  • Accepted file extension for uploading
$wgFileExtensions = [ 'png', 'jpg', 'jpeg', 'tiff', 'ogg', 'mp3', 'doc', 'xls', 'ppt', 'docx', 'xlsx', 'pptx', 'sxc', 'pdf' ];

The ownership of folder used for uploading needs correct permissions.

sudo chown –R http:http images/
sudo chmod –R 755 images/

Composer

Composer is a dependency manager for PHP. Some MediaWiKi extensions will require Composer for installation.

Composer Installation

1. Composer Merge Plugin requires Composer 1.1.0 or newer, but doesn’t currently support Composer 2.0.

2. Download composer-setup.php in the base directory of the PHP installation, e.g., /usr/local/etc/php74

sudo /usr/local/bin/php74 -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

3. Run the setup script to download composer.phar with version 1.10.20.

sudo /usr/local/bin/php74 composer-setup.php --version=1.10.20

Itsy Package Management System

1. Follow the instructions to install ipkg on Synology.

cd /tmpwget http://ipkg.nslu2-linux.org/feeds/optware/syno-i686/cross/unstable/syno-i686-bootstrap_1.2-7_i686.xshchmod +x syno-i686-bootstrap_1.2-7_i686.xshsh syno-i686-bootstrap_1.2-7_i686.xshipkg update

2. Install Ghostscript and Xpdf packages

ipkg install ghostscript
ipkg install xpdf

MediaWiKi Extension

Math

1. Download Math extension and extract the file(s) by tar in a directory called Math in the extensions/ folder.

2. Add following code at the bottom of LocalSettings.php.

wfLoadExtension( 'Math' );

3. Run the update script from the base directory of the MediaWiKi installation

/usr/local/bin/php74 maintenance/update.php

MSCalendar

1. Download MsCalendar extension and extract the file(s) by tar in a directory called MsCalendar in the extensions/folder.

2. Add following code at the bottom of LocalSettings.php.

wfLoadExtension( 'Math' );

3. Run the update script from the base directory of the MediaWiKi installation

/usr/local/bin/php74 maintenance/update.php

Mermaid and Semantic MediaWiki (SMW)

1. Add a new file named composer.local.json in the base directory of the MediaWiKi installation.

2. Modify the content as shown below.

{
"require": {
"mediawiki/semantic-media-wiki": "~3.2.2",
"mediawiki/mermaid": "~3.0"`
}
}

3. Run the update script from the base directory of the MediaWiKi installation

/usr/local/bin/php74 /usr/local/etc/php70/composer.phar update --no-dev

4. Add following code at the bottom of LocalSettings.php.

wfLoadExtension( 'Mermaid' );
enableSemantics( 'https://example.org/mediawiki' );

5. Run the update script from the base directory of the MediaWiKi installation

/usr/local/bin/php74 maintenance/update.php

6. Check the Special:Version page on your wiki and verify that the extension has been successfully updated.

PdfHandler

Prerequisites

This extension requires the following packages to be installed first:

Type which gs convert pdfinfo pdftotext command in your shell to see if you have the above installed first

Installation

1. Download PdfHandler extension and extract the file(s) by tar in a directory called PdfHandler in the extensions/folder.

2. Add following code in LocalSettings.php after installing Ghostscript and Xpdf by ipkg.

$wgMaxShellMemory = 1024000;
$wgPdfProcessor = '/opt/bin/gs';
$wgPdfPostProcessor = $wgImageMagickConvertCommand;;
$wgPdfInfo = '/opt/bin/pdfinfo';
$wgPdftoText = '/opt/bin/pdftotext';

3. Add following code at the bottom of LocalSettings.php.

wfLoadExtension( 'PdfHandler' );

VisualEditor

1. If you’re using the latest stable version of MediaWiki you will not need to download the VisualEditor extension.

2. VisualEditor needs to be installed with:

wfLoadExtension( 'VisualEditor' );

3. Allow VisualEditor on page titles containing slashes

If you are serving MediaWiKi from Apache2, you will need to add the following to your top level server configuration (often a <VirtualHost> section in /var/packages/Apache2.4/target/usr/local/etc/apache24/conf/httpd24.confor similar):

AllowEncodedSlashes NoDecode

If you do not, then VisualEditor will complain that Error contacting the Parsoid/RESTBase server when editing a page title containing a slash.

SyntaxHighlight

1. If you’re using the latest stable version of MediaWiki you will not need to download the SyntaxHighlight extension.

1.1 Otherwise, download SyntaxHighlight extension and extract the file(s) by tar in a directory called SyntaxHighlight_GeSHi in the extensions/ folder.

2. Add following code at the bottom of LocalSettings.php.

wfLoadExtension( 'SyntaxHighlight_GeSHi' );

3. Install pip, the package installer for Python, and upgrade pip to the latest version.

sudo -i
python3 -m ensurepip
python3 -m pip install --upgrade pip

4. Install Pygments by pip

/var/packages/py3k/target/usr/local/bin/pip3 install Pygments

5. Add following code in LocalSettings.php.

$wgPygmentizePath = "/var/packages/py3k/target/usr/local/bin/pygmentize";

Back up MediaWiKi

Reference: Manual:Backing up a wiki

MediaWiki stores important data in two places:

1. Database: Pages and their contents, users and their syntaxhighlightferences, metadata, search index, etc.

2. File system: Software configuration files, custom skins, extensions, images (including deleted images), etc.

MariaDB

MySQL databases are easy to backup using the mysqldump command:

mysqldump -u<username> -p<password> <database name> > <output file>

To restore a backup you will need to have a clean database. Then run:

mysql -u<username> -p<password> <database name> < <input file>

You can also perform both of these tasks using phpMyAdmin

File System

MediaWiki stores other components of the wiki in the file system where this is more appropriate than insertion into the database, for example, site configuration files (LocalSettings.php, image files, skin customization, extension files, and etc.

tar zcvhf mediawiki.tgz /volume1/mediawiki

Restore MediaWiKi

Reference: Manual:Restoring a wiki from backup

Namespace

Reference: Manual:Using custom namespaces

Namespace

define("NS_WINDOWS", 3000);
define("NS_WINDOWS_TALK", 3001);
define("NS_MACOS", 3002);
define("NS_MACOS_TALK", 3003);
define("NS_LINUX", 3004);
define("NS_LINUX_TALK", 3005);
$wgExtraNamespaces[NS_WINDOWS] = "Windows";
$wgExtraNamespaces[NS_WINDOWS_TALK] = "Windows_Talk";
$wgExtraNamespaces[NS_MACOS] = "macOS";
$wgExtraNamespaces[NS_MACOS_TALK] = "macOS_Talk";
$wgExtraNamespaces[NS_LINUX] = "Linux";
$wgExtraNamespaces[NS_LINUX_TALK] = "Linux_Talk";
$wgNamespacesWithSubpages[NS_MAIN] = true;
$wgNamespacesWithSubpages[NS_WINDOWS] = true;
$wgNamespacesWithSubpages[NS_MACOS] = true;
$wgNamespacesWithSubpages[NS_LINUX] = true;
$wgContentNamespaces[] = NS_WINDOWS;
$wgContentNamespaces[] = NS_MACOS;
$wgContentNamespaces[] = NS_LINUX;

--

--