MediaWiki

MediaWiki
is a free and open source
wiki
software written in
PHP
, originally developed for
Wikipedia
.
MediaWiki
also
powers
this wiki—see also the
archwiki
repository.
Installation
To run MediaWiki you need three things:
the
mediawiki
package, which pulls in
PHP
,
a
web server
—such as
Apache HTTP Server
,
lighttpd
or
nginx
,
a database system—one of
MariaDB
,
MySQL
,
PostgreSQL
, or
SQLite
.
To install MediaWiki on
XAMPP
, see
mw:Manual:Installing MediaWiki on XAMPP
.
Configuration
The steps to achieve a working MediaWiki configuration involve editing the PHP settings and adding the MediaWiki configuration snippets.
PHP
MediaWiki requires the
iconv
and the
intl
extensions, so you need to uncomment
extension=iconv
and
extension=intl
in
/etc/php/php.ini
.
Optional dependencies:
For thumbnail rendering, install either
ImageMagick
or
php-gd
. If you choose the latter, you also need to uncomment
extension=gd
.
Enable the API for your DBMS:
If you use
MariaDB
, uncomment
extension=mysqli
.
If you use
PostgreSQL
, install
php-pgsql
and uncomment
extension=pgsql
.
If you use
SQLite
, install
php-sqlite
and uncomment
extension=pdo_sqlite
.
Second, tweak the session handling or you might get a fatal error (
PHP Fatal error: session_start(): Failed to initialize storage module[...]
) by finding the
session.save_path
path. A good choice can be
/var/lib/php/sessions
or
/tmp/
.
/etc/php/php.ini
session.save_path = "/var/lib/php/sessions"
You will need to create the directory if it does not exist and then restrict its permissions:
# mkdir -p /var/lib/php/sessions/
# chown http:http /var/lib/php/sessions
# chmod go-rwx /var/lib/php/sessions
If you use
PHP's open_basedir
and want to
allow file uploads
, you need to include
/var/lib/mediawiki/
(
mediawiki
symlinks
images/
to
/var/lib/mediawiki/
).
Web server
Apache
Follow
Apache HTTP Server#PHP
.
Copy
/etc/webapps/mediawiki/apache.example.conf
to
/etc/httpd/conf/extra/mediawiki.conf
and edit it as needed.
Add the following line to
/etc/httpd/conf/httpd.conf
:
Include conf/extra/mediawiki.conf
Restart
the
httpd.service
daemon.
Note
The default file from
/etc/webapps/mediawiki/apache.example.conf
will override the PHP
open_basedir
setting, possibly conflicting with other pages. This behavior can be changed by moving line with
php_admin_value open_basedir
between the
<Directory>
tags. Further, if you are running multiple applications that depend on the same server, this value could also be added to the
open_basedir
value in
/etc/php/php.ini
instead of
/etc/httpd/conf/extra/mediawiki.conf
.
Nginx
The factual accuracy of this article or section is disputed.
Reason:
/mw-config/index.php
should not be exposed, see
Talk:MediaWiki#/mw-config/index.php is exposed with Nginx config
. (Discuss in
Talk:MediaWiki
)
To get MediaWiki working with
Nginx
, create the following file:
/etc/nginx/mediawiki.conf
location / {
   index index.php;
   try_files $uri $uri/ @mediawiki;
}
location @mediawiki {
   rewrite ^/(.*)$ /index.php;
}
location ~ \.php$ {
   include /etc/nginx/fastcgi_params;
   fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
   fastcgi_index index.php;
   fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
   try_files $uri @mediawiki;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
   try_files $uri /index.php;
   expires max;
   log_not_found off;
}
# Restrictions based on the .htaccess files
location ~ ^/(cache|includes|maintenance|languages|serialized|tests|images/deleted)/ {
   deny all;
}
location ~ ^/(bin|docs|extensions|includes|maintenance|mw-config|resources|serialized|tests)/ {
   internal;
}
location ^~ /images/ {
   try_files $uri /index.php;
}
location ~ /\. {
   access_log off;
   log_not_found off; 
   deny all;
}
location /rest.php {
   try_files $uri $uri/ /rest.php?$args;
}
Ensure that
php-fpm
is installed and
php-fpm.service
is
started
.
Include a server directive, similar to this
/etc/nginx/nginx.conf
server {
  listen 80;
  server_name mediawiki;
  root /usr/share/webapps/mediawiki;
  index index.php;
  charset utf-8;
# For correct file uploads
  client_max_body_size    100m; # Equal or more than upload_max_filesize in /etc/php/php.ini
  client_body_timeout     60;
  include mediawiki.conf;

}
Finally,
restart
nginx.service
and
php-fpm.service
daemons.
Lighttpd
You should have
Lighttpd
installed and configured. "mod_alias" and "mod_rewrite" in server.modules array of lighttpd is required. Append to the lighttpd configuration file the following lines
/etc/lighttpd/lighttpd.conf
alias.url += ("/mediawiki" => "/usr/share/webapps/mediawiki/")
url.rewrite-once += (
                "^/mediawiki/wiki/upload/(.+)" => "/mediawiki/wiki/upload/$1",
                "^/mediawiki/wiki/$" => "/mediawiki/index.php",
                "^/mediawiki/wiki/([^?]*)(?:\?(.*))?" => "/mediawiki/index.php?title=$1&$2"
)
Restart
the
lighttpd.service
daemon.
Database
Set up a database server as explained in the article of your DBMS:
MariaDB
,
PostgreSQL
,
SQLite
or
MySQL
.
Note
For MariaDB/MySQL, MediaWiki uses
binary collation
, so you need to specify that collation when creating the database:
CREATE DATABASE mediawiki CHARACTER SET binary COLLATE binary;
If you have set a non-empty root password for the database server, MediaWiki can automatically create the database during the
next step
. (See
MariaDB#Reset the root password
for how to set this password retrospectively for MariaDB.)  Otherwise the database needs to be created manually - see
upstream instructions
.
Wiki setup
Now you need to set up your wiki by creating its database tables and configuration file,
LocalSettings.php
. There are two methods: from command line and from browser, the former being safer because it doesn't require you to expose the installer.
Warning
LocalSettings.php
contains database connection settings, such as the username and password, and the MediaWiki web-based updater password. Make sure only the
root
and
http
users have access to
/etc/webapps/mediawiki/LocalSettings.php
:
# chown root:http /etc/webapps/mediawiki/LocalSettings.php
# chmod 640 /etc/webapps/mediawiki/LocalSettings.php
This file defines the specific settings of your wiki. Whenever you upgrade the
mediawiki
package, it will not be replaced.
From command line
The install script has a lot of parameters, refer to
MediaWiki documentation
for full details. Here is a basic example:
The factual accuracy of this article or section is disputed.
Reason:
Setting passwords via command-line options is insecure as the passwords end up in shell logs and are visible in the list of system processes. (Discuss in
Talk:MediaWiki
)
# cd /etc/webapps/mediawiki/
# php maintenance/run.php install \
    --dbname=wikidb \
    --dbserver="localhost" \
    --installdbuser=root \
    --installdbpass=rootpassword \
    --dbuser=dbusername \
    --dbpass=dbuserpassword \
    --server="
http://wiki.example.com/
" \
    --scriptpath=/w \
    --lang=en \
    --pass=Adminpassword "Wiki Name" "Admin account name"
From browser
Open the wiki URL (usually
http://
your_server
/mediawiki/index.php
) in a browser and do the initial configuration. Follow
upstream instructions
.
The generated
LocalSettings.php
file is offered for download, save it to
/etc/webapps/mediawiki/LocalSettings.php
.
Since 1.38.0 it has a symbolic link included in
/usr/share/webapps/mediawiki/LocalSettings.php
.
LDAP Auth
Use
PluggableAuth
and
LDAP Stack
. Pay attention to "Compatibility Matrix" section. Currently LDAP works only with PluggableAuth-5.7.
You need to install and add to config ldap stack extensions and PluggableAuth:
Extension:PluggableAuth
Extension:LDAPProvider
Extension:LDAPAuthentication2
Extension:LDAPAuthorization
Extension:LDAPUserInfo
Extension:LDAPGroups
Then set up at least 3 variables:
$LDAPProviderDomainConfigProvider
- whole ldap config (can be in json file)
$wgPluggableAuth_Config
- list of auth plugins
$wgPluggableAuth_Config = array(
       array('plugin' => 'LDAPAuthentication2'),
       array('plugin' => 'LDAPAuthorization'),
);
and
$LDAPProviderDefaultDomain
Do not forget to run
php maintenance/update.php
after configuration.
Short URL
Short URL
feature allows the wiki articles to be accessed in SEO-friendly structure (like
http://example.org/wiki/Article
).
Below assumes that the URL structure used will be
/wiki/$1
, where
$1
is the article name.
Apache
Add rewrite rules to
/etc/httpd/conf/extra/mediawiki.conf
:
RewriteEngine On

# Short URL for wiki pages
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]

# Redirect / to Main Page
RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]
Restart
httpd.service
.
Nginx
Add rewrite rules to
/etc/nginx/mediawiki.conf
:
# Handling for Mediawiki REST API, see
mw:API:REST_API
location /rest.php/ {
	try_files $uri $uri/ /w/rest.php?$query_string;
}

# Handling for the article path (pretty URLs)
location /wiki/ {
	rewrite ^/wiki/(?<pagename>.*)$ /index.php;
}

# Explicit access to the root website, redirect to main page (adapt as needed)
location = / {
	return 301 /wiki/Main_Page;
}
Restart
nginx.service
.
LocalSettings.php
Append to
/etc/webapps/mediawiki/LocalSettings.php
:
$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true;
You may also want to rewrite the article's page action URLs. To do so, append below instead:
## Use "/wiki/$action/$1" for page actions
$actions = [
	'view',
	'edit',
	'watch',
	'unwatch',
	'delete',
	'revert',
	'rollback',
	'protect',
	'unprotect',
	'markpatrolled',
	'render',
	'submit',
	'history',
	'purge',
	'info',
];

foreach ( $actions as $action ) {
  $wgActionPaths[$action] = "/wiki/$action/$1";
}

# Keep "/wiki/$1" for viewing articles
$wgActionPaths['view'] = "/wiki/$1";
$wgArticlePath = $wgActionPaths['view'];
$wgUsePathInfo = true;
Tip
If you host a public wiki, you can generate necessary short URL configuration by submitting to
MediaWiki ShortURL Builder
.
Upgrading
See
mw:Manual:Upgrading
, and do not forget to run:
# cd /usr/share/webapps/mediawiki
# php maintenance/run.php update
Tips and tricks
Unicode
Check that
PHP
,
Apache HTTP Server
and
MariaDB
all use UTF-8. Otherwise you may face strange bugs because of encoding mismatch.
VisualEditor
The VisualEditor MediaWiki extension provides a rich-text editor for MediaWiki. Follow
mw:Extension:VisualEditor
to install it.