Difference between revisions of "MediaWiki"

From ArchWiki
Jump to navigation Jump to search
m (Mathematics (texvc): link to texvc package)
(update warning, MediaWiki 1.32 was released)
 
(103 intermediate revisions by 33 users not shown)
Line 1: Line 1:
[[Category:Web Server]]
+
[[Category:Wiki software]]
{{Note| If you are using xampp, instead of [[LAMP]], there are different steps you need to take after installing. More info [https://www.mediawiki.org/wiki/Manual:Running_MediaWiki_on_XAMPP#381 here] }}
+
[[ja:MediaWiki]]
 +
{{Note|MediaWiki is not fully compatible with PHP 7.3 yet.[https://www.mediawiki.org/wiki/Compatibility#PHP][https://phabricator.wikimedia.org/project/view/3494/]}}
 +
 
 +
[https://www.mediawiki.org/wiki/MediaWiki MediaWiki] is a free and open source wiki software written in [[PHP]], originally developed for Wikipedia. It also powers this wiki (see [[Special:Version]] and the [https://github.com/archlinux/archwiki GitHub repository]).
 +
 
 
== Installation ==
 
== Installation ==
  
You need to have a web server installed, configured to be able to use {{Pkg|php}}. You can follow the [[LAMP]] guide for that purpose.
+
To run MediaWiki you need three things:
 +
 
 +
* the {{pkg|mediawiki}} package, which pulls in [[PHP]]
 +
* a web server – [[Apache]], [[Nginx]] or [[Lighttpd]]
 +
* a database system – [[MySQL]], [[PostgreSQL]] or [[SQLite]]
  
[[Pacman|Install]] the {{pkg|php-gd}}, {{pkg|php-intl}}, {{pkg|php-xcache}} and {{pkg|mediawiki}}, all available from the [[official repositories]].
+
To install MediaWiki on [[XAMPP]], see [[mw:Manual:Installing MediaWiki on XAMPP]]
  
Instead of {{pkg|mysql}} you can use sqlite (which requires {{pkg|php-sqlite}} and {{pkg|sqlite}}) or {{pkg|postgresql}}.
+
== Configuration ==
  
{{Note|Since PHP 5.1.0, SQLite depends on PDO. You should uncomment the following line in your php.ini if you wish to use SQLite with Mediawiki:
+
The steps to achieve a working MediaWiki configuration involve editing the PHP settings and adding the MediaWiki configuration snippets.
  
'''extension1=pdo_sqlite.so'''}}
+
=== PHP ===
  
==Configuration==
+
MediaWiki requires the {{ic|iconv}} extension, so you need to uncomment {{ic|1=extension=iconv}} in {{ic|/etc/php/php.ini}}.
First, adjust the {{ic|open_basedir}} in {{ic|/etc/php/php.ini}} to include the webapps directory (allows '''update.php''' to be run from the command line):
+
 
{{hc|/etc/php/php.ini|<nowiki>
+
Optional dependencies:
open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/
+
 
</nowiki>}}
+
* For thumbnail rendering, install either [[ImageMagick]] or {{Pkg|php-gd}}. If you choose the latter, you also need to uncomment {{ic|1=extension=gd}}.
Then, still on {{ic|/etc/php/php.ini}}, look for the {{ic|Dynamic Extensions}} section  and uncomment {{ic|1=;extension=gd.so}}, uncomment {{ic|1=;extension=intl.so}} and add {{ic|1=extension=xcache.so}}.
+
* For more efficient [[mw:Unicode normalization considerations|Unicode normalization]], install {{Pkg|php-intl}} and uncomment {{ic|1=extension=intl}}.
 +
 
 +
Enable the API for your DBMS:
 +
 
 +
* If you use [[MariaDB]], uncomment {{ic|1=extension=mysqli}}.
 +
* If you use [[PostgreSQL]], install {{Pkg|php-pgsql}} and uncomment {{ic|1=extension=pgsql}}.
 +
* If you use [[SQLite]], install {{Pkg|php-sqlite}} and uncomment {{ic|1=extension=pdo_sqlite}}.
 +
 
 +
Second, tweak the session handling or you might get a fatal error ({{ic|PHP Fatal error: session_start(): Failed to initialize storage module[...]}}) by finding the {{ic|session.save_path}} path. A good choice can be {{ic|/var/lib/php/sessions}} or {{ic|/tmp/}}.
 +
 
 +
{{hc|/etc/php/php.ini|2=
 +
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#Configuration|PHP's open_basedir]] and want to [[mw:Manual:Configuring file uploads|allow file uploads]], you need to include {{ic|/var/lib/mediawiki/}} ({{Pkg|mediawiki}} symlinks {{ic|images/}} to {{ic|/var/lib/mediawiki/}}).
  
Now do the steps corresponding to your web server.
 
 
=== Web server ===
 
=== Web server ===
 +
 
==== Apache ====
 
==== Apache ====
Create {{ic|/etc/webapps/mediawiki/httpd-mediawiki.conf}} from the provided example {{ic|apache.example.conf}} in the same directory. Edit it to remove the {{ic|php_admin_value open_basedir}} line, which is already in {{ic|php.ini}}.
 
  
*Add the following lines to {{ic|/etc/httpd/conf/httpd.conf}}
+
Follow [[Apache HTTP Server#PHP]].
{{bc|
+
 
LoadModule php5_module modules/libphp5.so
+
Copy {{ic|/etc/webapps/mediawiki/apache.example.conf}} to {{ic|/etc/httpd/conf/extra/mediawiki.conf}} and edit it as needed.
Include conf/extra/php5_module.conf
+
 
Include /etc/webapps/mediawiki/httpd-mediawiki.conf
+
Add the following line to {{ic|/etc/httpd/conf/httpd.conf}}:
}}
+
 
 +
Include conf/extra/mediawiki.conf
  
* Adjust permissions in {{ic|/usr/share/webapps/mediawiki/.htaccess}}, e.g. to
+
[[Restart]] the {{ic|httpd.service}} daemon.
{{bc|allow from all}}
 
  
[[Daemons|Restart]] the {{ic|httpd.service}} daemon.
+
{{Note|The default file from {{ic|/etc/webapps/mediawiki/apache.example.conf}} will overwrite the PHP open_basedir setting, possibly conflicting with other pages. This behavior can be changed by moving line starting with {{ic|php_admin_value}} between the {{ic|<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 {{ic|/etc/php/php.ini}} instead of {{ic|/etc/httpd/conf/extra/mediawiki.conf}}}}
  
 
==== Nginx ====
 
==== Nginx ====
To get MediaWiki working with Nginx, create the following file:
+
 
 +
To get MediaWiki working with [[Nginx]], create the following file:
  
 
{{hc|/etc/nginx/mediawiki.conf|<nowiki>
 
{{hc|/etc/nginx/mediawiki.conf|<nowiki>
 
 
location / {
 
location / {
 
   index index.php;
 
   index index.php;
Line 47: Line 74:
 
}
 
}
 
location @mediawiki {
 
location @mediawiki {
   rewrite ^/(.*)$ /index.php?title=$1&$args;
+
   rewrite ^/(.*)$ /index.php;
 
}
 
}
 
location ~ \.php5?$ {
 
location ~ \.php5?$ {
   include fastcgi.conf;
+
   include /etc/nginx/fastcgi_params;
   fastcgi_pass php;
+
   fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
 +
  fastcgi_index index.php5;
 +
  fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
 +
  try_files $uri @mediawiki;
 
}
 
}
 
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
 
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
Line 74: Line 104:
 
}
 
}
 
</nowiki>}}
 
</nowiki>}}
Ensure that {{ic|php-fpm}} is installed, and in your {{ic|/etc/nginx/nginx.conf}} file, ensure that you have an {{ic|upstream}} directive named {{ic|php}}, similar to this one:
 
  
{{hc|/etc/nginx/nginx.conf|<nowiki>
+
Ensure that {{Pkg|php-fpm}} is installed and [[start]]ed.
upstream php {
 
  server unix:/var/run/php-fpm/php-fpm.sock;
 
}
 
</nowiki>}}
 
  
 
Include a server directive, similar to this
 
Include a server directive, similar to this
Line 98: Line 123:
 
}
 
}
 
}}
 
}}
 +
 +
Finally, [[restart]] {{ic|nginx.service}} and {{ic|php-fpm.service}} daemons.
  
 
==== Lighttpd ====
 
==== 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
 
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
 +
 
{{hc|/etc/lighttpd/lighttpd.conf|<nowiki>
 
{{hc|/etc/lighttpd/lighttpd.conf|<nowiki>
 
alias.url += ("/mediawiki" => "/usr/share/webapps/mediawiki/")
 
alias.url += ("/mediawiki" => "/usr/share/webapps/mediawiki/")
Line 109: Line 138:
 
)
 
)
 
</nowiki>}}
 
</nowiki>}}
[[Daemons|Restart]] the {{ic|lighttpd.service}} daemon.
+
 
 +
[[Restart]] the {{ic|lighttpd.service}} daemon.
 +
 
 +
=== Database ===
 +
 
 +
Set up a database server as explained in the article of your DBMS: [[MySQL]], [[PostgreSQL]] or [[SQLite]].
 +
 
 +
MediaWiki can automatically create the database, if you supply the database root password,  during the [[#LocalSettings.php|next step]]. Otherwise the database needs to be created manually, see [[mw:Manual:Installing_MediaWiki#Create_a_database|upstream instructions]].
  
 
=== LocalSettings.php ===
 
=== LocalSettings.php ===
Open the wiki url (is {{ic|http://''your_server''/mediawiki/}}) in a browser and do the initial setup to create {{ic|LocalSettings.php}}. Then save it to {{ic|/usr/share/webapps/mediawiki/LocalSettings.php}}.
+
 
 +
Open the wiki url (usually {{ic|http://''your_server''/mediawiki/}}) in a browser and do the initial configuration. Follow [[mw:Manual:Config_script|upstream instructions]].
 +
 
 +
The generated {{ic|LocalSettings.php}} file is offered for download, save it to {{ic|/usr/share/webapps/mediawiki/LocalSettings.php}}. This file defines the specific settings of your wiki. Whenever you upgrade the {{pkg|mediawiki}} package, it is not replaced.
  
 
== Tips and tricks ==
 
== Tips and tricks ==
 +
 
=== Mathematics (texvc) ===
 
=== Mathematics (texvc) ===
  
Usually installing {{Pkg|texvc}} and enabling it in the config are enough:
+
Usually installing {{Pkg|texvc}} and enabling it in the config is enough:
  
{{bc|1=$wgUseTeX = true;}}
+
$wgUseTeX = true;
  
 
If you get problems, try to increase limits for shell commands:
 
If you get problems, try to increase limits for shell commands:
{{bc|<nowiki>
+
 
$wgMaxShellMemory = 8000000;
+
{{bc|1=
$wgMaxShellFileSize = 1000000;
+
$wgMaxShellMemory = 8000000;
$wgMaxShellTime = 300;
+
$wgMaxShellFileSize = 1000000;
</nowiki>}}
+
$wgMaxShellTime = 300;
 +
}}
  
 
=== Unicode ===
 
=== Unicode ===
  
 
Check that php, apache and mysql uses UTF-8. Otherwise you may face strange bugs because of encoding mismatch.
 
Check that php, apache and mysql uses 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.
 +
 +
You will also need the [[mw:Parsoid|Parsoid]] Node.js backend, which is available from the [[AUR]] as {{AUR|parsoid-git}}.
 +
 +
Adjust the path to MediaWiki in {{ic|/usr/share/webapps/parsoid/api/localsettings.js}}:
 +
 +
parsoidConfig.setInterwiki( 'localhost', '<nowiki>http://localhost/mediawiki/api.php</nowiki>' );
 +
 +
After that [[enable]] and start {{ic|parsoid.service}}.
 +
 +
Alternatively, one may also use the {{AUR|parsoid}} package, and configure the service via the yaml file, where the following lines should be present:
 +
 +
{{hc|/usr/share/webapps/parsoid/config.yaml|<nowiki>
 +
uri: `'http://localhost/mediawiki/api.php'`
 +
domain: 'localhost'
 +
</nowiki>}}
 +
 +
The matching part in the mediawiki settings:
 +
 +
{{hc|/usr/share/webapps/mediawiki/LocalSettings.php|<nowiki>
 +
$wgVirtualRestConfig['modules']['parsoid'] = array(
 +
  // URL to the Parsoid instance - use port 8142 if you use the Debian package - the parameter 'URL' was first used but is now deprecated (string)
 +
  'url' => 'http://localhost:8000/',
 +
  // Parsoid "domain" (string, optional) - MediaWiki >= 1.26
 +
  'domain' => 'localhost',
 +
  // Parsoid "prefix" (string, optional) - deprecated since MediaWiki 1.26, use 'domain'
 +
  'prefix' => 'localhost',
 +
  // Forward cookies in the case of private wikis (string or false, optional)
 +
  'forwardCookies' => false,
 +
  // request timeout in seconds (integer or null, optional)
 +
  'timeout' => null,
 +
  // Parsoid HTTP proxy (string or null, optional)
 +
  'HTTPProxy' => null,
 +
  // whether to parse URL as if they were meant for RESTBase (boolean or null, optional)
 +
  'restbaseCompat' => null,
 +
);
 +
</nowiki>}}
 +
 +
After configuration, the {{ic|parsoid}} service may be started (restarted) and (if not done yet) enabled.

Latest revision as of 04:56, 17 January 2019

Note: MediaWiki is not fully compatible with PHP 7.3 yet.[1][2]

MediaWiki is a free and open source wiki software written in PHP, originally developed for Wikipedia. It also powers this wiki (see Special:Version and the GitHub repository).

Installation

To run MediaWiki you need three things:

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 extension, so you need to uncomment extension=iconv in /etc/php/php.ini.

Optional dependencies:

Enable the API for your DBMS:

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 overwrite the PHP open_basedir setting, possibly conflicting with other pages. This behavior can be changed by moving line starting with php_admin_value 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

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 ~ \.php5?$ {
   include /etc/nginx/fastcgi_params;
   fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
   fastcgi_index index.php5;
   fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
   try_files $uri @mediawiki;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
   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;
}

Ensure that php-fpm is installed and 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: MySQL, PostgreSQL or SQLite.

MediaWiki can automatically create the database, if you supply the database root password, during the next step. Otherwise the database needs to be created manually, see upstream instructions.

LocalSettings.php

Open the wiki url (usually http://your_server/mediawiki/) in a browser and do the initial configuration. Follow upstream instructions.

The generated LocalSettings.php file is offered for download, save it to /usr/share/webapps/mediawiki/LocalSettings.php. This file defines the specific settings of your wiki. Whenever you upgrade the mediawiki package, it is not replaced.

Tips and tricks

Mathematics (texvc)

Usually installing texvc and enabling it in the config is enough:

$wgUseTeX = true;

If you get problems, try to increase limits for shell commands:

$wgMaxShellMemory = 8000000;
$wgMaxShellFileSize = 1000000;
$wgMaxShellTime = 300;

Unicode

Check that php, apache and mysql uses 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.

You will also need the Parsoid Node.js backend, which is available from the AUR as parsoid-gitAUR.

Adjust the path to MediaWiki in /usr/share/webapps/parsoid/api/localsettings.js:

parsoidConfig.setInterwiki( 'localhost', 'http://localhost/mediawiki/api.php' );

After that enable and start parsoid.service.

Alternatively, one may also use the parsoidAUR package, and configure the service via the yaml file, where the following lines should be present:

/usr/share/webapps/parsoid/config.yaml
uri: `'http://localhost/mediawiki/api.php'`
domain: 'localhost'

The matching part in the mediawiki settings:

/usr/share/webapps/mediawiki/LocalSettings.php
$wgVirtualRestConfig['modules']['parsoid'] = array(
  // URL to the Parsoid instance - use port 8142 if you use the Debian package - the parameter 'URL' was first used but is now deprecated (string)
  'url' => 'http://localhost:8000/',
  // Parsoid "domain" (string, optional) - MediaWiki >= 1.26
  'domain' => 'localhost',
  // Parsoid "prefix" (string, optional) - deprecated since MediaWiki 1.26, use 'domain'
  'prefix' => 'localhost',
  // Forward cookies in the case of private wikis (string or false, optional)
  'forwardCookies' => false,
  // request timeout in seconds (integer or null, optional)
  'timeout' => null,
  // Parsoid HTTP proxy (string or null, optional)
  'HTTPProxy' => null,
  // whether to parse URL as if they were meant for RESTBase (boolean or null, optional)
  'restbaseCompat' => null,
);

After configuration, the parsoid service may be started (restarted) and (if not done yet) enabled.