MediaWiki
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.