Difference between revisions of "MediaWiki"

From ArchWiki
Jump to: navigation, search
(Moved the open_basedir step, since is the same on any web server.)
(PHP)
(23 intermediate revisions by 7 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] }}
+
{{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]] guide. Then [[pacman|Install]] {{pkg|php-gd}} and uncomment {{ic|1=;extension=gd.so}} in {{ic|php.ini}}, same for {{pkg|php-intl}} (needs icu) and {{pkg|php-xcache}} (here add {{ic|1=extension=xcache.so}}) and finally install {{pkg|mediawiki}}, all available from the [[official repositories]].
+
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.
  
Instead of {{pkg|mysql}} you can install {{pkg|sqlite3}} or {{pkg|postgresql}}.
+
[[Pacman|Install]] the {{pkg|php-gd}}, {{pkg|php-intl}}, {{pkg|php-xcache}} and {{pkg|mediawiki}}, all available from the [[official repositories]].
 +
 
 +
Instead of {{pkg|mysql}} you can use sqlite (which requires {{pkg|php-sqlite}} and {{pkg|sqlite}}) or {{pkg|postgresql}}.
 +
 
 +
{{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:
 +
 
 +
'''extension1=pdo_sqlite.so'''}}
  
 
==Configuration==
 
==Configuration==
 +
 +
The steps to achieve a working MediaWiki configuration involve editing the PHP settings and adding the MediaWiki configuration snippets.
 +
 +
===PHP===
 
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):
 
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):
{{bc|1=open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/}}
+
{{hc|/etc/php/php.ini|<nowiki>
 +
open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/
 +
</nowiki>}}
 +
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}}.
 +
 
 +
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|<nowiki>
 +
session.save_path = "/var/lib/php/sessions"
 +
</nowiki>}}
 +
 
 +
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}}
  
Now do the steps corresponding to your 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|open_basedir}} line, which is already in {{ic|php.ini}}.
+
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}}
 
*Add the following lines to {{ic|/etc/httpd/conf/httpd.conf}}
Line 23: Line 47:
  
 
* Adjust permissions in {{ic|/usr/share/webapps/mediawiki/.htaccess}}, e.g. to  
 
* Adjust permissions in {{ic|/usr/share/webapps/mediawiki/.htaccess}}, e.g. to  
{{ic|allow from all}}
+
{{bc|allow from all}}
  
[[Pacman|Restart]] the {{ic|httpd.service}} daemon.
+
[[Daemons|Restart]] the {{ic|httpd.service}} daemon.
  
Open the wiki in a browser and do the initial setup to create {{ic|LocalSettings.php}}. Then save it to {{ic|/usr/share/webapps/mediawiki/LocalSettings.php}}.
+
==== Nginx ====
 
+
To get MediaWiki working with [[Nginx]], create the following file:
=== Nginx ===
+
To get MediaWiki working with Nginx, create the following file:
+
  
 
{{hc|/etc/nginx/mediawiki.conf|<nowiki>
 
{{hc|/etc/nginx/mediawiki.conf|<nowiki>
Line 36: Line 58:
 
location / {
 
location / {
 
   index index.php;
 
   index index.php;
   try_files $uri @mediawiki;
+
   try_files $uri $uri/ @mediawiki;
 
}
 
}
 
location @mediawiki {
 
location @mediawiki {
   rewrite ^/([^?]*)(?:\?(.*))? /index.php?title=$1$2 last;
+
   rewrite ^/(.*)$ /index.php?title=$1&$args;
 
}
 
}
location ~ \.php?$ {
+
location ~ \.php5?$ {
 
   include fastcgi.conf;
 
   include fastcgi.conf;
 
   fastcgi_pass php;
 
   fastcgi_pass php;
Line 50: Line 72:
 
   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)/ {
 +
   deny all;
 +
}
 +
location ^~ ^/(bin|docs|extensions|includes|maintenance|mw-config|resources|serialized|tests)/ {
 +
  internal;
 +
}
 +
location ^~ /images/ {
 +
  try_files $uri /index.php;
 
}
 
}
location ^~ /cache/ {
+
location ~ /\. {
 +
  access_log off;
 +
  log_not_found off;
 
   deny all;
 
   deny all;
 
}
 
}
 
</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:
+
Ensure that {{Pkg|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>
 
{{hc|/etc/nginx/nginx.conf|<nowiki>
Line 73: Line 104:
 
   root /usr/share/webapps/mediawiki;
 
   root /usr/share/webapps/mediawiki;
 
   index index.php;
 
   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;
 
   include mediawiki.conf;
 +
 
}
 
}
 
}}
 
}}
 +
 +
Finally, restart the {{ic|nginx.service}} daemon:
 +
{{bc|# systemctl restart nginx.service}}
 +
 +
==== 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>}}
 +
[[Daemons|Restart]] the {{ic|lighttpd.service}} daemon.
 +
 +
=== 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}}.
  
 
== Tips and tricks ==
 
== Tips and tricks ==
 
=== 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;
+
 
 +
{{bc|1=$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;
+
{{bc|<nowiki>
  $wgMaxShellFileSize = 1000000;
+
$wgMaxShellMemory = 8000000;
  $wgMaxShellTime = 300;
+
$wgMaxShellFileSize = 1000000;
 +
$wgMaxShellTime = 300;
 +
</nowiki>}}
  
 
=== 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.

Revision as of 06:46, 24 November 2013

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 installed, configured to be able to use php. You can follow the LAMP guide for that purpose.

Install the php-gd, php-intl, php-xcache and mediawiki, all available from the official repositories.

Instead of mysql you can use sqlite (which requires php-sqlite and sqlite) or postgresql.

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: extension1=pdo_sqlite.so

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 webapps directory (allows update.php to be run from the command line):

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

Then, still on /etc/php/php.ini, look for the Dynamic Extensions section and uncomment ;extension=gd.so, uncomment ;extension=intl.so and add extension=xcache.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

Create /etc/webapps/mediawiki/httpd-mediawiki.conf from the provided example apache.example.conf in the same directory. Edit it to remove the php_admin_value open_basedir line, which is already in php.ini.

  • Add the following lines to /etc/httpd/conf/httpd.conf
LoadModule php5_module modules/libphp5.so
Include conf/extra/php5_module.conf
Include /etc/webapps/mediawiki/httpd-mediawiki.conf
  • Adjust permissions in /usr/share/webapps/mediawiki/.htaccess, e.g. to
allow from all

Restart the httpd.service daemon.

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?title=$1&$args;
}
location ~ \.php5?$ {
   include fastcgi.conf;
   fastcgi_pass php;
}
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 in your /etc/nginx/nginx.conf file, ensure that you have an upstream directive named php, similar to this one:

/etc/nginx/nginx.conf
upstream php {
   server unix:/var/run/php-fpm/php-fpm.sock;
}

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 the nginx.service daemon:

# systemctl restart nginx.service

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.

LocalSettings.php

Open the wiki url (is http://your_server/mediawiki/) in a browser and do the initial setup to create LocalSettings.php. Then save it to /usr/share/webapps/mediawiki/LocalSettings.php.

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.