MediaWiki是一个免费、开源的维基软件,用 PHP 写成;原本是为维基百科开发的。它也给 archwiki 提供了帮助。(详情查看 Special:Version 和 GitHub repository)。
安装
为了运行 MediaWiki 你需要三个组件:
- mediawiki包 包,PHP 会作为它的依赖安装
- 一个网站服务器 – 例如 Apache HTTP Server、nginx 和 lighttpd
- 一个数据库系统 – MariaDB、PostgreSQL、SQLite 或 MySQL
如果要在 XAMPP 上安装 MediaWiki,参见 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 需要 iconv
插件,所以需要把 /etc/php/php.ini
里面的 extension=iconv
取消注释。
可选插件:
- 为了渲染缩略图,安装 ImageMagick 或者 php-gd包(二选一)。如果安装的是后者,需要取消注释
extension=gd
。 - 为了更高效率的 Unicode normalization,取消注释
extension=intl
。
启用你的数据库管理系统的 API:
- 如果是 MariaDB,取消注释
extension=mysqli
。 - 如果是 PostgreSQL,安装 php-pgsql包 并取消注释
extension=pgsql
。 - 如果是 SQLite,安装 php-sqlite包 并取消注释
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"
如果那个目录不存在,你要手动创建它,并更改权限:
# mkdir -p /var/lib/php/sessions/ # chown http:http /var/lib/php/sessions # chmod go-rwx /var/lib/php/sessions
如果你使用了 PHP's open_basedir 并想 允许文件上传,你需要把 /var/lib/mediawiki/
添加到里面去 (mediawiki包 为 images/
创建了指向 /var/lib/mediawiki/
的符号链接)。
网站服务器
Apache
按照 Apache HTTP Server#PHP 配置 PHP。
复制 /etc/webapps/mediawiki/apache.example.conf
到 /etc/httpd/conf/extra/mediawiki.conf
并按需要修改它。
添加下面这一行到 /etc/httpd/conf/httpd.conf
:
Include conf/extra/mediawiki.conf
重启 httpd.service
。
/etc/webapps/mediawiki/apache.example.conf
会覆盖 PHP 的 open_basedir 设置,可能会和其他页面产生冲突。 可以通过把以 php_admin_value
开头的行移到 <Directory>
标签之间来避免这个问题。而如果你运行了多个依赖同一个 server 的应用,你可以把这个值添加到 /etc/php/php.ini
里的 open_basedir 里,而不仅仅是放在 /etc/httpd/conf/extra/mediawiki.conf
里。Nginx
对于 Nginx,请创建这样的一个文件:
/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; }
请确保已经安装了 php-fpm包 并 启动 了 php-fpm7.service
。
在/etc/nginx/nginx.conf
添加一个 server 块,类似这样的:
/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; }
最后,restart nginx.service
和 php-fpm.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.
数据库
按照你所需要的数据库管理系统(DBMS)的文章配置数据库服务器:MariaDB、PostgreSQL、SQLite 或 MySQL。
如果数据库密码不为空,MediaWiki会自动创建数据库(设置 MariaDB 密码的方法在 MariaDB#Reset the root password) 。否则你就需要手动创建数据库,详情参考: upstream instructions。
LocalSettings.php
在浏览器里打开 wiki 的 URL (通常是 http://your_server/mediawiki/index.php
) 并进行初始化配置。参考upstream instructions的步骤。
生成的 LocalSettings.php
文件是用来下载的,保存它到 /usr/share/webapps/mediawiki/LocalSettings.php
。
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
.
/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.
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.
升级
参考 mw:Manual:Upgrading, 不要忘记运行:
# cd /usr/share/webapps/mediawiki # php maintenance/update.php
Tips and tricks
数学 (texvc)
通常来说,安装 texvc包[损坏的链接:package not found] 并在配置文件里启用它就可以了:
$wgUseTeX = true;
如果遇到问题,尝试提高以下的 shell 命令限制值:
$wgMaxShellMemory = 8000000; $wgMaxShellFileSize = 1000000; $wgMaxShellTime = 300;
Unicode
请确保PHP, Apache HTTP Server 和 MariaDB都用的是 UTF-8 编码。否则可能遇到因为编码不匹配导致的奇怪bug。
VisualEditor
The VisualEditor MediaWiki extension provides a rich-text editor for MediaWiki. Follow mw:Extension:VisualEditor to install it.