Install MediaWiki

MediaWiki is the most popular wiki package and is the open source software that powers Wikipedia, among a great many other sites. This article covers installing MediaWiki to a UNPM Server.

This article assumes that MediaWiki is to be installed to a sub-directory called, though it can be installed to a sub-directory of any name or depth (additional sub-directories). Note that the WikiMedia Foundation recommends against installation to a site's root directory as this will break many aspects of the site.

Package-configs files
Create the  files   and  :

username@servername:~$ sudo nano /etc/nginx/package-configs/mediawiki.conf

Add to the new file:

username@servername:~$ sudo nano /etc/nginx/package-configs/mediawiki_https.conf

Add to the new file:

Sites-available file
Open the sites-available file for the domain:

username@servername:~$ sudo nano /etc/nginx/sites-available/example.com

In the HTTP server block, add:

In the HTTPS server block, add:

404 error_page
Note that if the  directive is being used to redirect 404 errors, be sure it is in the   block:

If it is directly in the  block, MediaWiki will not attempt to create pages when a wrong page is requested.

Create MediaWiki database and database user
Create a MediaWiki database and database user: username@servername:~$ sudo mysql -uroot -p MariaDB [(none)]> create database databasename; MariaDB [(none)]> grant all on databasename.* to 'databasenameusername'@'localhost' identified by 'databasenameusernamepassword'; MariaDB [(none)]> exit

Note that the,   and   will be required for the MediaWiki configuration process.

Install Mediawiki
Mediawiki will require a few packages to be installed to run:

username@servername:~$ sudo aptitude install imagemagick php5-intl username@servername:~$ sudo nano /etc/php5/fpm/php-fpm.conf

Add to the file:

Test nginx and restart services: username@servername:~$ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful username@servername:~$ sudo service php5-fpm restart username@servername:~$ sudo service nginx reload * Reloading nginx configuration nginx                                  [ OK ]

Download Mediawiki: username@servername:~$ wget https://releases.wikimedia.org/mediawiki/1.25/mediawiki-1.25.1.tar.gz username@servername:~$ tar -xzf mediawiki-1.25.1.tar.gz username@servername:~$ mv mediawiki-1.25.1/ /var/www/example.com/public/wiki username@servername:~$ find /var/www/example.com/public/wiki/ -type d | xargs chmod 775 username@servername:~$ find /var/www/example.com/public/wiki/ -type f | xargs chmod 664 username@servername:~$ sudo chown -R www-data:www-data /var/www/example.com/public/wiki/ username@servername:~$ rm mediawiki-1.25.1.tar.gz

Navigate to secure  https://www.example.com/wiki  and complete the Mediawiki installation. Most admins will prefer to use the 'Authorized editors only' option under 'User rights profile:'. Select 'PHP object caching (APC, XCache or WinCache)' in the Advanced Configuration options and be sure to sign up for update notifications.

LocalSettings.php
After completing the online setup, MediaWiki will prompt to download the  file. This is the main configuration file for MediaWiki. It is easiest to open the file in a text editor and then copy and paste the contents into the  file on the server. However, before doing that, the file still requires at least a few edits.

To support loading MediaWiki in non-secure sessions, but require secure session for logging in, change:

Enable :

To create a user rights management system better suited to smaller wikis, change:

Then, just below the permissions created by MediaWiki, add:

The  user group means all users, including anonymous users.

Below that, add:

Now paste the entire contents from the computer's text editor to the  file on the server: username@servername:~$ nano /var/www/example.com/public/wiki/LocalSettings.php

Note that depending on the operating system and editor used, the code may paste in without things such as returns between paragraphs. This does happen with Notepad++ in Windows 7, but can easily be fixed by first pasting into a new Notepad++ tab and copying from there.

Configuring MediaWiki
MediaWiki configuration is different from most of the popular PHP packages. Configuring is done through the  file, extensions, which must be installed server-side with accompanied   entries, and various different hard-to-find pages in the web interface. The MediaWiki Manual is an invaluable resource. Below are some simple and common extension and configuration settings.

Sidebar
To edit the MediaWiki Sidebar, while logged in with an admin account, simply navigate to  https://www.example.com/wiki/MediaWiki:Sidebar .

Disable page counts
By default, MediaWiki will display page counts at the bottom of every page. This can be disabled with the following:

username@servername:~$ nano /var/www/example.com/public/wiki/LocalSettings.php

Add to the bottom of the file:

Change logo image
The logo image location is set in  with the   directive, for which the default is. Replacing  with a different image while using the same name will be overwritten when updating MediaWiki, so it is better to use a file in a different location. MediaWiki updates generally ignore anything in the  directory, so putting the logo there and setting   is a reasonable solution, though other locations may work just as well.

MobileFrontend extension
Although there are options to automatically detect mobile devices and display a mobile-friendly theme, the disadvantage of this feature is it requires disabling caching unless an additional domain is used, such as placing an m in the subdomain. A compromise is to install the MobileFrontend extension which creates a Mobile view link at the bottom of every page. It is important to check the extension page and verify the latest version.

username@servername:~$ wget https://extdist.wmflabs.org/dist/extensions/MobileFrontend-REL1_25-c193468.tar.gz username@servername:~$ tar -xzf MobileFrontend-REL1_25-c193468.tar.gz username@servername:~$ mv MobileFrontend/ /var/www/example.com/public/wiki/extensions/ username@servername:~$ find /var/www/example.com/public/wiki/extensions/MobileFrontend/ -type d | xargs chmod 775 username@servername:~$ find /var/www/example.com/public/wiki/extensions/MobileFrontend/ -type f | xargs chmod 664 username@servername:~$ sudo chown -R www-data:www-data /var/www/example.com/public/wiki/extensions/MobileFrontend/ username@servername:~$ rm MobileFrontend-REL1_25-c193468.tar.gz username@servername:~$ nano /var/www/example.com/public/wiki/LocalSettings.php

Add to the bottom of the file:

Tracking with Piwik
Piwik may be used by simply enabling and configuring the MediaWiki:Common.js feature or by installing the Piwik extension.

MediaWiki:Common.js
The easiest way to use Piwik to track users of the wiki is to simply use the Common.js feature of MediaWiki. Enable it in :

username@servername:~$ nano /var/www/example.com/public/wiki/LocalSettings.php

Add to the file:

Navigate to  https://www.example.com/wiki/MediaWiki:Common.js  while logged in as an administrator and add the Piwik javascript code:

Refer to the Piwik article for an explanation of  and   usage.

Piwik Integration extension
If more sophisticated tracking is required, such as ignoring certain users or user types, Using the Piwik extension may be preferable to the Common.js method. It is important to note that this extension may not support tracking while in Mobile view due to a bug.

Email notifications
If the server does not have any form of mail server installed, the  setting may be used to configure an SMTP server for sending email.

username@servername:~$ nano /var/www/example.com/public/wiki/LocalSettings.php

Add the following array:

Add the following PEAR packages so that PHP can support sending mail:

username@servername:~$ sudo pear install Mail username@servername:~$ sudo pear install Net_SMTP

File upload extension management
Use  to add file extensions available for upload by adding the following, edited as desired, to  :

Note that there are also options available to permit all extensions except those blacklisted. More information on this and other features related to uploads is available at [//www.mediawiki.org/wiki/Manual:Configuring_file_uploads Mediawiki Manual:Configuring file uploads].

It will be necessary to tell nginx to serve these filetypes as files. Change the  block in both   and   to support the desired filetypes:

Increase Mediawiki max file upload size
Mediawiki is set by default with a max upload file size of 100 MB, calculated as 1024*1024*100. To change this, in addition to necessary configuration changes in  and , change the   parameter to other than default by adding the following to  :

AntiSpam
MediaWiki now installs with the [//www.mediawiki.org/wiki/Extension:ConfirmEdit ConfirmEdit] extension that includes [//www.mediawiki.org/wiki/Extension:QuestyCaptcha QuestyCaptcha], a configurable bot-checking tool that can be applied to specific pages, such as only the account creation page, or to every page. QustyCaptcha is still in Beta, but should work well on most installations.

Upgrading MediaWiki
Upgrading MediaWiki is done through the command line. For minor version upgrades, a patch file may be made available, otherwise a complete reinstall from backup is essentially performed. The best way to find the locations of an update's files and options is from the announcement email, presumably subscribed to during the setup process.

Maintenance mode
To prevent user edits to the wiki during upgrade, which might be saved to the old database, place the following statement at the bottom of.

username@servername:~$ nano /var/www/example.com/public/wiki/LocalSettings.php

Upgrading via patch
The first step is to backup the database. Log in to phpMyAdmin as the root MySQL user. Select the database used by MediaWiki and navigate to the Operations page. Enter the name of the backup database in the Copy database to: field, leaving the default selections for copying and select Go</tt>. It may be a good idea to include the MediaWiki version number in the backup name for future reference.

Backup the  directory, download the patch from the location stated in the update notification email, decompress to the   directory, run a dry run to see what files are modified, backup any files to be changed by the patch that have been customized, then run the patch. Thea actual location of the patch will depend on current version and the version to be upgraded to and can be found somewhere in this directory.

username@servername:~$ cp -rp /var/www/example.com/public/wiki/ /var/www/example.com/public/wiki-backup/ username@servername:~$ wget https://releases.wikimedia.org/mediawiki/1.24/mediawiki-1.24.2.patch.gz username@servername:~$ zcat mediawiki-1.24.2.patch.gz > /var/www/example.com/public/wiki/mediawiki-1.24.2.patch username@servername:~$ cd /var/www/example.com/public/wiki/ username@servername:/var/www/example.com/public/wiki$ patch -p1 --dry-run < mediawiki-1.24.2.patch username@servername:/var/www/example.com/public/wiki$ patch -p1 < mediawiki-1.24.2.patch username@servername:/var/www/example.com/public/wiki$ cd ~ username@servername:~$ sudo su www-data $ php /var/www/example.com/public/wiki/maintenance/update.php $ exit

After verifying the wiki is functioning properly, archive the original wiki.

username@servername:~$ mkdir /var/www/example.com/backup/wiki username@servername:~$ mv /var/www/example.com/public/wiki-backup /var/www/example.com/backup/wiki/mediawiki-1.24.1

Upgrade without patch
To upgrade to versions without a patch, near complete reinstallation is performed. Note that this procedure transfers current MediaWiki settings and sets up the new MediaWiki version on a copy of the working database. This is to facilitate easy recovery to the currently functioning wiki since no changes are made to the wiki or its database.

Install new version to new directory
The actual new version will depend on what version it is desired to upgrade to. All versions of MediaWiki may be found here.

username@servername:~$ wget https://releases.wikimedia.org/mediawiki/1.24/mediawiki-1.24.2.tar.gz username@servername:~$ tar -xzf mediawiki-1.24.2.tar.gz -C /var/www/example.com/public/ username@servername:~$ find /var/www/example.com/public/mediawiki-1.24.2/ -type d | xargs chmod 775 username@servername:~$ find /var/www/example.com/public/mediawiki-1.24.2/ -type f | xargs chmod 664 username@servername:~$ sudo chown -R www-data:www-data /var/www/example.com/public/mediawiki-1.24.2/ username@servername:~$ cp -p /var/www/example.com/public/wiki/LocalSettings.php /var/www/example.com/public/mediawiki-1.24.2/LocalSettings.php username@servername:~$ cp -rpfu /var/www/example.com/public/wiki/extensions/* /var/www/example.com/public/mediawiki-1.24.2/extensions username@servername:~$ cp -rpfu /var/www/example.com/public/wiki/images/* /var/www/example.com/public/mediawiki-1.24.2/images username@servername:~$ cp -rpfu /var/www/example.com/public/wiki/skins/* /var/www/example.com/public/mediawiki-1.24.2/skins

Note that any other additional files not a part of the MediaWiki package should also be copied to the new directory. Files that have been customized should be customized again using the file in the new installation.

Copy database to new database
Log in to phpMyAdmin as the root MySQL user. Select the database used by MediaWiki and navigate to the Operations</tt> page. Enter the name of the new database in the Copy database to:</tt> field, leaving the default selections for copying and select Go</tt>

Navigate to phpMyAdmin home page and select Users</tt>. Click Edit privileges</tt> next to the user assigned to the original MediaWiki database. Under Database-specific privileges</tt>, select the new database in the Add privileges on the following database:</tt> drop-down menu. In the following page, click Check all</tt>, then uncheck GRANT</tt> and click Go</tt>.

Now update the name of the database in the new  file:

username@servername:~$ nano /var/www/example.com/public/mediawiki-1.24.2/LocalSettings.php

Change:

Archive the original  installation, install the new installation in its place and run the update script:

username@servername:~$ mkdir /var/www/example.com/backup/wiki/ username@servername:~$ mv /var/www/example.com/public/wiki /var/www/example.com/backup/wiki/mediawiki-1.24.1 username@servername:~$ mv /var/www/example.com/public/mediawiki-1.24.2/ /var/www/example.com/public/wiki username@servername:~$ sudo su www-data $ php /var/www/example.com/public/wiki/maintenance/update.php $ exit

Navigate to the wiki and verify it is functioning properly. If it is not functioning properly and the problem cannot repaired, then restore the archived version until the update can be successfully performed.