帮助:MediaWiki 安装:修订间差异
来自陋室
更多操作
删除的内容 添加的内容
小 添加模板 |
Maintenance script(留言 | 贡献) 基于本站实际配置统一校对安装说明 |
||
| (未显示2个用户的10个中间版本) | |||
| 第1行: | 第1行: | ||
'''说明''' 本指南结合 MediaWiki 官方文档与实际部署经验,概述通用安装流程,并结合本站(learn.houjue.digital)当前环境给出可直接复用的参数与命令。请始终以 [https://www.mediawiki.org/wiki/Manual:Installing_MediaWiki 官方安装指南] 为权威来源,并根据自己的环境调整命令与路径。 |
|||
这个页面介绍了本站的 MediaWiki 的安装笔记. |
|||
== 服务器配置 == |
|||
'''服务器提供商''': 腾讯云-轻量云(轻量应用服务器) |
|||
== 环境准备 == |
|||
'''地域和可用区''': 新加坡 | 新加坡一区 |
|||
=== 系统与组件 === |
|||
本站当前运行环境如下(可按需替换为你的实际版本): |
|||
* 操作系统:Debian 12 (bookworm) |
|||
* Web 服务器:Nginx 1.22.x |
|||
* PHP:8.2.x(PHP-FPM) |
|||
* 数据库:MariaDB 10.11.x |
|||
常用版本检查命令: |
|||
'''实例规格''': |
|||
* '''CPU''': 2核 |
|||
* '''内存''': 2GB |
|||
* '''系统盘''': SSD云硬盘 50GB |
|||
* '''流量包''': 1024GB/月(峰值带宽 30Mbps) |
|||
== 服务器环境 == |
|||
=== 操作系统 === |
|||
'''镜像名称''': Debian |
|||
'''操作系统''': Debian 12.0 64bit |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
cat /etc/os-release |
cat /etc/os-release |
||
nginx -v |
|||
sudo apt update |
|||
sudo apt upgrade |
|||
</syntaxhighlight> |
|||
=== 服务器软件 === |
|||
* '''宝塔Linux面板''': 正式版9.4.0 |
|||
<syntaxhighlight lang="bash"> |
|||
wget -O install_panel.sh https://download.bt.cn/install/install_panel.sh && bash install_panel.sh ed8484bec |
|||
</syntaxhighlight> |
|||
* '''Apache 2.4.62 (PHP+fpm)''' |
|||
<syntaxhighlight lang="bash"> |
|||
which apache2 |
|||
apache2 -v |
|||
</syntaxhighlight> |
|||
* '''MySQL 5.7.44'''(MediaWiki最低要求5.7,官方推荐MongoDB) |
|||
<syntaxhighlight lang="bash"> |
|||
which mysql |
|||
systemctl status mysql |
|||
</syntaxhighlight> |
|||
* '''PHP 8.2.27'''(MediaWiki最低要求8.1) |
|||
<syntaxhighlight lang="bash"> |
|||
which php |
|||
php -v |
php -v |
||
mysql --version |
|||
</syntaxhighlight> |
|||
* '''phpMyAdmin 5.2'''(可通过宝塔安装) |
|||
* '''ffmpeg 6.1'''(可通过宝塔安装) |
|||
<syntaxhighlight lang="bash"> |
|||
which ffmpeg |
|||
ffmpeg -version |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
=== 依赖 |
=== 更新与依赖 === |
||
根据本站当前部署(Debian 12 + Nginx + PHP 8.2 FPM + MariaDB),建议按以下方式更新与安装依赖: |
|||
==== php-wikidiff2 ==== |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
sudo apt update && sudo apt upgrade -y |
|||
apt-get install php-wikidiff2 |
|||
sudo apt install nginx mariadb-server php8.2-fpm php8.2-cli php8.2-mysql php8.2-gd php8.2-mbstring php8.2-xml php8.2-curl php8.2-zip php8.2-intl php8.2-apcu unzip git -y |
|||
find /usr/lib/ -name wikidiff2.so |
|||
# 多媒体与差异对比工具 |
|||
nano /www/server/php/82/etc/php.ini |
|||
sudo apt install ffmpeg poppler-utils imagemagick php-wikidiff2 -y |
|||
extension=/usr/lib/php/20220829/wikidiff2.so |
|||
php -m | grep wikidiff2 |
|||
</syntaxhighlight> |
|||
<syntaxhighlight lang="php"> |
|||
$wgDiffEngine = "wikidiff2"; |
|||
$wgDiff3 = "/usr/bin/diff3"; |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
如需启用 Lua/时间线/乐谱等扩展,可按需补充: |
|||
==== LilyPond ==== |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
# Scribunto |
|||
sudo apt update |
|||
sudo apt install |
sudo apt install php-luasandbox -y |
||
# EasyTimeline/Score 等 |
|||
lilypond --version |
|||
sudo apt install perl ploticus lilypond ghostscript -y |
|||
</syntaxhighlight> |
|||
<syntaxhighlight lang="php"> |
|||
wfLoadExtension( 'Score' ); |
|||
$wgScoreTrim = true; |
|||
$wgImageMagickConvertCommand = '/usr/bin/convert'; |
|||
$wgScoreSafeMode = false; |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
说明:本站使用 Nginx + PHP-FPM,如需 Apache 请改用对应包与配置;PHP-FPM 请确保与 Nginx 配置匹配。 |
|||
==== Ghostscript ==== |
|||
<syntaxhighlight lang="bash"> |
|||
sudo apt update |
|||
sudo apt install ghostscript |
|||
gs --version |
|||
</syntaxhighlight> |
|||
== 安装步骤 == |
|||
=== 1. 下载 MediaWiki(通用流程) === |
|||
从官方 https://releases.wikimedia.org 下载当前稳定版本。示例命令: |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
cd /var/www |
|||
sudo apt update |
|||
wget https://releases.wikimedia.org/mediawiki/1.45/mediawiki-1.45.0.tar.gz |
|||
sudo apt install fluidsynth |
|||
tar -xzvf mediawiki-1.45.0.tar.gz |
|||
fluidsynth --version |
|||
mv mediawiki-1.45.0 mediawiki |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
本站实际路径:<code>/var/www/mediawiki</code>,Web 用户为 <code>www-data</code>。 |
|||
==== LAME ==== |
|||
<syntaxhighlight lang="bash"> |
|||
sudo apt update |
|||
sudo apt install lame |
|||
lame --version |
|||
</syntaxhighlight> |
|||
<syntaxhighlight lang="php"> |
|||
$wgScoreLame = '/usr/bin/lame'; |
|||
</syntaxhighlight> |
|||
=== 2. 创建数据库与用户(通用流程) === |
|||
==== php-luasandbox ==== |
|||
登录数据库创建专用数据库与账号: |
|||
<syntaxhighlight lang="bash"> |
|||
<syntaxhighlight lang="sql"> |
|||
sudo apt update |
|||
CREATE DATABASE my_wiki CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; |
|||
sudo apt install php-luasandbox -y |
|||
CREATE USER 'wikiuser'@'localhost' IDENTIFIED BY '强密码'; |
|||
find /usr/lib/php/ -name "luasandbox.so" |
|||
GRANT ALL PRIVILEGES ON my_wiki.* TO 'wikiuser'@'localhost'; |
|||
nano /www/server/php/82/etc/php.ini |
|||
FLUSH PRIVILEGES; |
|||
extension=/usr/lib/php/20220829/luasandbox.so |
|||
php -m | grep luasandbox |
|||
</syntaxhighlight> |
|||
<syntaxhighlight lang="php"> |
|||
wfLoadExtension( 'Scribunto' ); |
|||
$wgScribuntoEngineConf['luasandbox']['memoryLimit'] = 50 * 1024 * 1024; |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
本站实际数据库配置(见 <code>/var/www/learn.php</code>): |
|||
==== Composer ==== |
|||
* 数据库:<code>learn</code> |
|||
<syntaxhighlight lang="bash"> |
|||
* 用户:<code>learn</code> |
|||
composer update --no-dev |
|||
* 主机:<code>localhost</code> |
|||
</syntaxhighlight> |
|||
=== 3. 运行安装向导(通用流程) === |
|||
== 服务器配置 == |
|||
在浏览器打开 <code>https://<你的域名或IP>/mw-config/</code>,安装向导会依次要求填写环境检测、数据库信息、站点名称、管理员账号、上传目录等。 |
|||
=== Apache相关 === |
|||
完成后会生成 <code>LocalSettings.php</code>,请放到 MediaWiki 根目录。 |
|||
'''禁用防跨站攻击 (open_basedir)''' |
|||
'''启用HTTPS防窜站''' |
|||
'''TLS 1.0和1.1禁用''' |
|||
'''伪静态配置''' |
|||
<syntaxhighlight lang="apache"> |
|||
RewriteEngine On |
|||
RewriteCond %{HTTPS} off |
|||
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] |
|||
RewriteCond %{REQUEST_URI} !\.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|less)$ [NC] |
|||
RewriteCond %{REQUEST_URI} !^/load.php [NC] |
|||
RewriteCond %{REQUEST_URI} !^/api.php [NC] |
|||
RewriteRule ^w/(.*)$ /index.php?title=$1 [L,QSA] |
|||
RewriteCond %{REQUEST_FILENAME} !-f |
|||
RewriteCond %{REQUEST_FILENAME} !-d |
|||
RewriteRule ^(.*)$ /index.php [L,QSA] |
|||
</syntaxhighlight> |
|||
<syntaxhighlight lang="php"> |
|||
wfLoadExtension( 'UrlShortener' ); |
|||
本站实际配置: |
|||
$wgUrlShortenerTemplate = '/r/$1'; |
|||
* <code>$wgServer = "https://learn.houjue.digital";</code> |
|||
$wgUrlShortenerServer = "false"; |
|||
* <code>$wgScriptPath = "";</code> |
|||
$wgUrlShortenerEnableQrCode = true; |
|||
* <code>$wgArticlePath = "/wiki/$1";</code> |
|||
$wgUrlShortenerQrCodeShortenLimit = 200; |
|||
* 上传目录:<code>/sgcos/images</code>(映射为 <code>/images</code>) |
|||
=== 4. 完成安装与安全加固(通用流程) === |
|||
$actions = [ |
|||
上传 LocalSettings 后即可通过站点访问。 |
|||
'view', |
|||
* 锁定安装目录:<code>chmod -R 700 /var/www/mediawiki/mw-config</code> |
|||
'edit', |
|||
* 确保 <code>LocalSettings.php</code> 权限为 600,Web 服务器可读。 |
|||
'watch', |
|||
* 关闭 config 目录写权限: |
|||
'unwatch', |
|||
<syntaxhighlight lang="bash"> |
|||
'delete', |
|||
chmod a-w /var/www/mediawiki/config |
|||
'revert', |
|||
'rollback', |
|||
'protect', |
|||
'unprotect', |
|||
'markpatrolled', |
|||
'render', |
|||
'submit', |
|||
'history', |
|||
'purge', |
|||
'info', |
|||
]; |
|||
foreach ($actions as $action) { |
|||
$wgActionPaths[$action] = "/w/$action/$1"; |
|||
} |
|||
$wgActionPaths['view'] = "/w/$1"; |
|||
$wgArticlePath = $wgActionPaths['view']; |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
== 后续依赖与扩展 == |
|||
=== php-wikidiff2 === |
|||
改善差异显示,安装命令: |
|||
=== Apache安全配置 === |
|||
<syntaxhighlight lang="apache"> |
|||
<Directory /www/wwwroot/lib/images/> |
|||
Options -ExecCGI -Indexes |
|||
AllowOverride None |
|||
<FilesMatch "\.(php|php5|pl|py|jsp|asp|htm|html|cgi|sh)$"> |
|||
Require all denied |
|||
</FilesMatch> |
|||
Header always set X-Content-Type-Options "nosniff" |
|||
</Directory> |
|||
</syntaxhighlight> |
|||
=== MySQL相关 === |
|||
'''官方建议''': |
|||
* 将所有表转为 InnoDB |
|||
* 将所有表转为 utf8mb4 |
|||
=== PHP相关 === |
|||
'''需要启用的插件'''(部分已默认启用) |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
sudo apt install php-wikidiff2 -y |
|||
php -m |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
配置: |
|||
<syntaxhighlight lang="php"> |
<syntaxhighlight lang="php"> |
||
$wgDiffEngine = 'wikidiff2'; |
|||
Core date libxml openssl pcre sqlite3 zlib bcmath ctype curl dom filter ftp gd gettext hash iconv intl json mbstring SPL session pcntl standard mysqlnd PDO pdo_mysql pdo_sqlite Phar posix random Reflection mysqli shmop SimpleXML soap sockets sodium sysvsem tokenizer xml xmlreader xmlwriter wikidiff2 luasandbox zip imagick fileinfo apcu exif calendar |
|||
$wgDiff3 = '/usr/bin/diff3'; |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
=== php-luasandbox 与 Scribunto === |
|||
'''需要解除禁用的函数''' |
|||
安装 Lua 沙箱: |
|||
<syntaxhighlight lang="php"> |
|||
<syntaxhighlight lang="bash"> |
|||
proc_open |
|||
sudo apt install php-luasandbox -y |
|||
popen |
|||
putenv |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
启用扩展: |
|||
== 站点配置 == |
|||
=== 数据库信息安全 === |
|||
'''LocalSettings.php''' |
|||
<syntaxhighlight lang="php"> |
<syntaxhighlight lang="php"> |
||
wfLoadExtension('Scribunto'); |
|||
include('/www/wwwroot/lib.php'); |
|||
$wgScribuntoEngineConf['luasandbox']['memoryLimit'] = 50 * 1024 * 1024; |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
=== 多媒体工具 === |
|||
'''lib.php''' |
|||
* ffmpeg:<code>sudo apt install ffmpeg -y</code> |
|||
<syntaxhighlight lang="php"> |
|||
* poppler-utils(PDF 处理):<code>sudo apt install poppler-utils -y</code> |
|||
<?php |
|||
* Composer(依赖管理):<code>curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer</code> |
|||
$wgDBserver = 'localhost'; |
|||
* EasyTimeline/Score/PdfHandler 等扩展可根据需要分别安装 ploticus、perl、lilypond、ghostscript、imagemagick 等依赖。 |
|||
$wgDBname = ''; |
|||
$wgDBuser = ''; |
|||
$wgDBpassword = ''; |
|||
?> |
|||
</syntaxhighlight> |
|||
== HTTPS 与短链接 == |
|||
本站使用 Nginx,短链接与 HTTPS 参考: |
|||
<syntaxhighlight lang="php"> |
|||
<syntaxhighlight lang="nginx"> |
|||
$wgLogos = [ |
|||
# 强制 HTTPS |
|||
'1x' => "$wgResourceBasePath/Libary-4l.png", |
|||
return 301 https://$host$request_uri; |
|||
'icon' => "$wgResourceBasePath/Libary-4l.png", |
|||
]; |
|||
# MediaWiki 路由(示例,需结合你的站点结构) |
|||
$wgFavicon = "$wgResourceBasePath/images/logos/Libary-4l.png"; |
|||
location /wiki/ { |
|||
$wgAppleTouchIcon = "$wgResourceBasePath/images/logos/Libary-4l.png"; |
|||
try_files $uri $uri/ /index.php?$args; |
|||
} |
|||
$wgFooterIcons['logo'] = [ |
|||
location ~ \.php$ { |
|||
'yourcustomicon' => [ |
|||
include snippets/fastcgi-php.conf; |
|||
'src' => '/images/logos/Libary-1ll.png ', |
|||
fastcgi_pass unix:/run/php/php8.2-fpm.sock; |
|||
'url' => $wgServer, |
|||
} |
|||
'alt' => 'Logo', |
|||
'height' => '31', |
|||
'width' => '68', |
|||
], |
|||
]; |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
配合以下 LocalSettings: |
|||
=== 移动端皮肤 === |
|||
<syntaxhighlight lang="php"> |
<syntaxhighlight lang="php"> |
||
$ |
$wgScriptPath = ''; |
||
$wgArticlePath = '/wiki/$1'; |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
== 性能与维护 == |
|||
* 使用缓存(APCu/Redis)加速页面与消息 |
|||
* 启用 <code>$wgMainCacheType</code>、<code>$wgParserCacheType</code> 等缓存参数 |
|||
* 定期运行维护脚本: |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
php maintenance/run.php update.php |
php /var/www/mediawiki/maintenance/run.php update.php |
||
php maintenance/run.php rebuildrecentchanges.php |
php /var/www/mediawiki/maintenance/run.php rebuildrecentchanges.php |
||
php maintenance/run.php |
php /var/www/mediawiki/maintenance/run.php refreshLinks.php |
||
php maintenance/run.php rebuildtextindex.php |
php /var/www/mediawiki/maintenance/run.php rebuildtextindex.php |
||
php maintenance/run.php |
php /var/www/mediawiki/maintenance/run.php runJobs.php |
||
php maintenance/run.php cleanupTitles.php --dry-run |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
== |
== 故障排查 == |
||
* 页面渲染成 WikiText:检查 PHP-FPM/Nginx 是否正常、LocalSettings 是否可读 |
|||
https://www.mediawiki.org/wiki/Download/zh |
|||
* 安装向导无法完成:检查文件夹权限,确保 <code>mw-config</code> 可写且临时可执行 |
|||
https://www.bt.cn/new/download.html |
|||
* 文件上传失败:核实上传目录与权限(本站为 <code>/sgcos/images</code>)以及 PHP 限制与 <code>$wgFileExtensions</code> 设置 |
|||
https://zh.wikipedia.org/wiki/Wikipedia:%E9%A6%96%E9%A1%B5 |
|||
* 数据库连接出错:确认凭据、字符集(utf8mb4)及正确的数据库主机 |
|||
https://www.mediawiki.org/wiki/Help:Formatting/zh |
|||
https://www.mediawiki.org/wiki/Help:Magic_words/zh |
|||
https://www.mediawiki.org/wiki/Help:Contents/zh |
|||
https://www.mediawiki.org/wiki/Manual:Contents/zh |
|||
https://www.huijiwiki.com/wiki/CommunityCenter |
|||
{{Template:站点帮助文档}} |
{{Template:站点帮助文档}} |
||