Difference between revisions of "MediaWiki"

From ArchWiki
Jump to: navigation, search
(Configuration)
(Nginx: Rewrite directly to /index.php, see https://www.mediawiki.org/wiki/Manual:Short_URL#Ampersand_.28.26.29_problem)
 
(81 intermediate revisions by 31 users not shown)
Line 1: Line 1:
[[Category:Web Server]]
+
[[Category:Web server]]
{{Note| If you are using xampp, 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| 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] }}
 +
 
 
== Installation ==
 
== Installation ==
  
Follow the [[LAMP|LAMP]] guide. Then [[pacman|Install]] {{pkg|php-gd}} and uncomment "extension=gd.so" in {{ic|php.ini}}, same for {{pkg|php-intl}} (needs icu) and {{pkg|php-xcache}} (here add "extension=xcache.so") and finally install {{pkg|mediawiki}}, all available from the [[official repositories]].
+
You need to have a web server, such as [[Apache]] installed, configured to be able to use [[PHP]].
  
Instead of {{pkg|mysql}} you can install {{pkg|sqlite3}} or {{pkg|postgresql}}.
+
[[Install]] the {{pkg|php-gd}}, {{pkg|php-intl}} and {{pkg|mediawiki}} packages.
 +
 
 +
You will also need a database system, such as [[MySQL]], [[PostgreSQL]] or [[SQLite]].
  
 
==Configuration==
 
==Configuration==
  
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|open_basedir}} line, which is already in {{ic|php.ini}}.
+
The steps to achieve a working MediaWiki configuration involve editing the PHP settings and adding the MediaWiki configuration snippets.
  
*Add the following lines to {{ic|/etc/httpd/conf/httpd.conf}}
+
===PHP===
LoadModule php5_module modules/libphp5.so
+
Include conf/extra/php5_module.conf
+
Include /etc/webapps/mediawiki/httpd-mediawiki.conf
+
* Adjust the open_basedir in {{ic|/etc/php/php.ini}} to include the webapps directory (allows update.php to be run from the command line):
+
  open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/
+
* Adjust permissions in {{ic|/usr/share/webapps/mediawiki/.htaccess}}, e.g. to
+
  allow from all
+
  
Restart apache with:
+
First, adjust the {{ic|open_basedir}} in {{ic|/etc/php/php.ini}} to include the mediawiki data directory ({{ic|/var/lib/mediawiki}} by default):
# systemctl restart httpd
+
  
Open the wiki in a browser and do the initial setup to create {{ic|/usr/share/webapps/mediawiki/LocalSettings.php}}.
+
{{hc|/etc/php/php.ini|2=
 +
open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/var/lib/mediawiki/
 +
}}
  
== Nginx ==
+
Then, also in {{ic|/etc/php/php.ini}}, uncomment the following lines: (in the {{ic|Dynamic Extensions}} section)
To get MediaWiki working with Nginx, create the following file at {{ic|/etc/nginx/mediawiki.conf}}:
+
extension=gd.so
 +
extension=intl.so
 +
extension=iconv.so
  
  location / {
+
{{Note|
 +
* If you would like to use SQLite as database, also uncomment {{ic|1=extension=pdo_sqlite.so}}.
 +
* If you would like to use MariaDB as database, also uncomment {{ic|1=extension=mysqli.so}}.
 +
}}
 +
 
 +
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 doesn't exist and then restrict its permissions:
 +
 
 +
{{bc|
 +
# mkdir -p /var/lib/php/sessions/
 +
# chown http:http /var/lib/php/sessions
 +
# chmod go-rwx /var/lib/php/sessions
 +
}}
 +
 
 +
=== Web server ===
 +
 
 +
==== Apache ====
 +
 
 +
Copy {{ic|/etc/webapps/mediawiki/apache.example.conf}} to {{ic|/etc/httpd/conf/extra/mediawiki.conf}} and edit it as needed.
 +
 
 +
Add the following lines to {{ic|/etc/httpd/conf/httpd.conf}}
 +
  Include conf/extra/mediawiki.conf
 +
 
 +
[[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, possibally conflicting with other pages. This behavior can be changed by moving line starting with {{ic|php_admin_value}} between the {{ic|<nowiki><Directory></nowiki>}} 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 ====
 +
 
 +
To get MediaWiki working with [[Nginx]], create the following file:
 +
 
 +
{{hc|/etc/nginx/mediawiki.conf|<nowiki>
 +
 
 +
location / {
 
   index index.php;
 
   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;
 
   try_files $uri @mediawiki;
}
+
}
location @mediawiki {
+
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
  rewrite ^/([^?]*)(?:\?(.*))? /index.php?title=$1$2 last;
+
}
+
location ~ \.php?$ {
+
  include fastcgi.conf;
+
  fastcgi_pass php;
+
}
+
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
+
 
   try_files $uri /index.php;
 
   try_files $uri /index.php;
 
   expires max;
 
   expires max;
 
   log_not_found off;
 
   log_not_found off;
}
+
}
location ^~ /maintenance/ {
+
# Restrictions based on the .htaccess files
  return 403;
+
location ^~ ^/(cache|includes|maintenance|languages|serialized|tests|images/deleted)/ {
}
+
location ^~ /cache/ {
+
 
   deny all;
 
   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;
 +
}
 +
</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:
+
Ensure that {{Pkg|php-fpm}} is installed and [[start]]ed.
  
upstream php {
+
Include a server directive, similar to this
  server unix:/var/run/php-fpm/php-fpm.sock;
+
}
+
  
Include a server directive, similar to this, in your {{ic|/etc/nginx/nginx.conf}} file:
+
{{hc|/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;
  
server {
+
}
  listen 80;
+
}}
  server_name mediawiki;
+
  root /usr/share/webapps/mediawiki;
+
  index index.php;
+
  include mediawiki.conf;
+
}
+
  
Finally, ensure that the {{ic|open_basedir}} directive in {{ic|/etc/php/php.ini}} includes {{ic|/usr/share/webapps}} and {{ic|/etc/webapps}}, or you might get "File not found" or "No input file specified" errors.
+
Finally, [[restart]] {{ic|nginx.service}} and {{ic|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
 +
 
 +
{{hc|/etc/lighttpd/lighttpd.conf|<nowiki>
 +
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"
 +
)
 +
</nowiki>}}
 +
 
 +
[[Restart]] the {{ic|lighttpd.service}} daemon.
 +
 
 +
=== Database ===
 +
 
 +
If the database server is already set up, MediaWiki can automatically create the database (provided that the database root password is supplied) 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 ===
 +
 
 +
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 ==
 
 
=== Mathematics (texvc) ===
 
=== Mathematics (texvc) ===
  
Usually installing texvc package and enabling it in config are enough:
+
Usually installing {{Pkg|texvc}} and enabling it in the config are enough:
  $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:
  $wgMaxShellMemory = 8000000;
+
 
  $wgMaxShellFileSize = 1000000;
+
{{bc|1=
  $wgMaxShellTime = 300;
+
$wgMaxShellMemory = 8000000;
 +
$wgMaxShellFileSize = 1000000;
 +
$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 ===
 +
 +
After following [https://www.mediawiki.org/wiki/Extension:VisualEditor this instruction] on how to install the VisualEditor, you need a backend nodejs application on your server, called [https://www.mediawiki.org/wiki/Parsoid Parsoid], to get it finally working.
 +
 +
Simply install {{AUR|parsoid-git}} from the [[AUR]] and adjust the path to your MediaWiki in following file:
 +
 +
{{hc|/usr/share/webapps/parsoid/api/localsettings.js|<nowiki>
 +
parsoidConfig.setInterwiki( 'localhost', 'http://localhost/mediawiki/api.php' );
 +
</nowiki>}}
 +
 +
After that simply [[enable]] and start {{ic|parsoid.service}}.

Latest revision as of 05:38, 4 June 2016

Note: If you are using xampp, instead of LAMP, there are different steps you need to take after installing. More info here

Installation

You need to have a web server, such as Apache installed, configured to be able to use PHP.

Install the php-gd, php-intl and mediawiki packages.

You will also need a database system, such as MySQL, PostgreSQL or SQLite.

Configuration

The steps to achieve a working MediaWiki configuration involve editing the PHP settings and adding the MediaWiki configuration snippets.

PHP

First, adjust the open_basedir in /etc/php/php.ini to include the mediawiki data directory (/var/lib/mediawiki by default):

/etc/php/php.ini
open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/var/lib/mediawiki/

Then, also in /etc/php/php.ini, uncomment the following lines: (in the Dynamic Extensions section)

extension=gd.so
extension=intl.so
extension=iconv.so
Note:
  • If you would like to use SQLite as database, also uncomment extension=pdo_sqlite.so.
  • If you would like to use MariaDB as database, also uncomment extension=mysqli.so.

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 doesn't 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

Web server

Apache

Copy /etc/webapps/mediawiki/apache.example.conf to /etc/httpd/conf/extra/mediawiki.conf and edit it as needed.

Add the following lines 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, possibally 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

If the database server is already set up, MediaWiki can automatically create the database (provided that the database root password is supplied) 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 are 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

After following this instruction on how to install the VisualEditor, you need a backend nodejs application on your server, called Parsoid, to get it finally working.

Simply install parsoid-gitAUR from the AUR and adjust the path to your MediaWiki in following file:

/usr/share/webapps/parsoid/api/localsettings.js
parsoidConfig.setInterwiki( 'localhost', 'http://localhost/mediawiki/api.php' );

After that simply enable and start parsoid.service.