帮助:MediaWiki安装指南:修订间差异
来自陋室
更多操作
删除的内容 添加的内容
完成 |
Maintenance script(留言 | 贡献) 帮助命名空间规范化:移除一级标题并修正渲染安全写法 |
||
| (未显示3个用户的14个中间版本) | |||
| 第1行: | 第1行: | ||
本页给出通用安装流程,并提供本站当前环境可复用的参数示例。实际部署请以官方文档为准。 |
|||
这个页面介绍了本站的 MediaWiki 的安装笔记. |
|||
== 服务器配置 == |
|||
'''服务器提供商''': 腾讯云-轻量云(轻量应用服务器) |
|||
== 参考环境 == |
|||
'''地域和可用区''': 新加坡 | 新加坡一区 |
|||
* 操作系统:Debian 12 |
|||
* Web 服务器:Nginx |
|||
* PHP:8.2(PHP-FPM) |
|||
* 数据库:MariaDB 10.11 |
|||
== 1. 安装系统依赖 == |
|||
'''实例规格''': |
|||
* '''CPU''': 2核 |
|||
* '''内存''': 2GB |
|||
* '''系统盘''': SSD云硬盘 50GB |
|||
* '''流量包''': 1024GB/月(峰值带宽 30Mbps) |
|||
== 服务器环境 == |
|||
=== 操作系统 === |
|||
'''镜像名称''': Debian |
|||
'''操作系统''': Debian 12.0 64bit |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
sudo apt update && sudo apt upgrade -y |
|||
cat /etc/os-release |
|||
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 |
|||
sudo apt update |
|||
sudo apt upgrade |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
== 2. 下载并解压 MediaWiki == |
|||
=== 服务器软件 === |
|||
* '''宝塔Linux面板''': 正式版9.4.0 |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
cd /var/www |
|||
wget -O install_panel.sh https://download.bt.cn/install/install_panel.sh && bash install_panel.sh ed8484bec |
|||
wget https://releases.wikimedia.org/mediawiki/1.45/mediawiki-1.45.0.tar.gz |
|||
</syntaxhighlight> |
|||
tar -xzvf mediawiki-1.45.0.tar.gz |
|||
* '''Apache 2.4.62 (PHP+fpm)''' |
|||
mv mediawiki-1.45.0 mediawiki |
|||
<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 |
|||
</syntaxhighlight> |
|||
* '''phpMyAdmin 5.2'''(可通过宝塔安装) |
|||
* '''ffmpeg 6.1'''(可通过宝塔安装) |
|||
<syntaxhighlight lang="bash"> |
|||
which ffmpeg |
|||
ffmpeg -version |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
== 3. 创建数据库与账号 == |
|||
=== 依赖软件安装 === |
|||
<syntaxhighlight lang="sql"> |
|||
==== php-wikidiff2 ==== |
|||
CREATE DATABASE my_wiki CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; |
|||
<syntaxhighlight lang="bash"> |
|||
CREATE USER 'wikiuser'@'localhost' IDENTIFIED BY '强密码'; |
|||
apt-get install php-wikidiff2 |
|||
GRANT ALL PRIVILEGES ON my_wiki.* TO 'wikiuser'@'localhost'; |
|||
find /usr/lib/ -name wikidiff2.so |
|||
FLUSH PRIVILEGES; |
|||
nano /www/server/php/82/etc/php.ini |
|||
extension=/usr/lib/php/20220829/wikidiff2.so |
|||
php -m | grep wikidiff2 |
|||
</syntaxhighlight> |
|||
<syntaxhighlight lang="php"> |
|||
$wgDiffEngine = "wikidiff2"; |
|||
$wgDiff3 = "/usr/bin/diff3"; |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
== 4. 运行安装向导 == |
|||
==== LilyPond ==== |
|||
访问:<code>https://你的域名/mw-config/</code> |
|||
<syntaxhighlight lang="bash"> |
|||
sudo apt update |
|||
sudo apt install lilypond |
|||
lilypond --version |
|||
</syntaxhighlight> |
|||
<syntaxhighlight lang="php"> |
|||
wfLoadExtension( 'Score' ); |
|||
$wgScoreTrim = true; |
|||
$wgImageMagickConvertCommand = '/usr/bin/convert'; |
|||
$wgScoreSafeMode = false; |
|||
</syntaxhighlight> |
|||
完成后将生成的 <code>LocalSettings.php</code> 放入站点根目录。 |
|||
==== Ghostscript ==== |
|||
<syntaxhighlight lang="bash"> |
|||
sudo apt update |
|||
sudo apt install ghostscript |
|||
gs --version |
|||
</syntaxhighlight> |
|||
== 5. 关键配置示例 == |
|||
==== FluidSynth ==== |
|||
<syntaxhighlight lang="bash"> |
|||
sudo apt update |
|||
sudo apt install fluidsynth |
|||
fluidsynth --version |
|||
</syntaxhighlight> |
|||
==== LAME ==== |
|||
<syntaxhighlight lang="bash"> |
|||
sudo apt update |
|||
sudo apt install lame |
|||
lame --version |
|||
</syntaxhighlight> |
|||
<syntaxhighlight lang="php"> |
<syntaxhighlight lang="php"> |
||
$ |
$wgScriptPath = ''; |
||
$wgArticlePath = '/wiki/$1'; |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
== 6. 常用安装后维护 == |
|||
==== php-luasandbox ==== |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
php /var/www/mediawiki/maintenance/run.php update.php |
|||
sudo apt update |
|||
php /var/www/mediawiki/maintenance/run.php rebuildrecentchanges.php |
|||
sudo apt install php-luasandbox -y |
|||
php /var/www/mediawiki/maintenance/run.php refreshLinks.php |
|||
find /usr/lib/php/ -name "luasandbox.so" |
|||
php /var/www/mediawiki/maintenance/run.php runJobs.php |
|||
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> |
||
== 7. 安全与排错 == |
|||
* 确保 <code>LocalSettings.php</code> 权限最小化。 |
|||
<syntaxhighlight lang="bash"> |
|||
* 上传失败时检查 PHP 上传大小限制与目录权限。 |
|||
composer update --no-dev |
|||
* 页面无法渲染时优先检查 PHP-FPM 与 Nginx 日志。 |
|||
</syntaxhighlight> |
|||
== |
== 官方文档 == |
||
* https://www.mediawiki.org/wiki/Manual:Installing_MediaWiki |
|||
=== Apache相关 === |
|||
'''禁用防跨站攻击 (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'; |
|||
$wgUrlShortenerServer = "false"; |
|||
$wgUrlShortenerEnableQrCode = true; |
|||
$wgUrlShortenerQrCodeShortenLimit = 200; |
|||
$actions = [ |
|||
'view', |
|||
'edit', |
|||
'watch', |
|||
'unwatch', |
|||
'delete', |
|||
'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> |
|||
=== SSL === |
|||
=== 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"> |
|||
php -m |
|||
</syntaxhighlight> |
|||
<syntaxhighlight lang="php"> |
|||
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 |
|||
</syntaxhighlight> |
|||
'''需要解除禁用的函数''' |
|||
<syntaxhighlight lang="php"> |
|||
proc_open |
|||
popen |
|||
putenv |
|||
</syntaxhighlight> |
|||
== 站点配置 == |
|||
=== 数据库信息安全 === |
|||
'''LocalSettings.php''' |
|||
<syntaxhighlight lang="php"> |
|||
include('/www/wwwroot/lib.php'); |
|||
</syntaxhighlight> |
|||
'''lib.php''' |
|||
<syntaxhighlight lang="php"> |
|||
<?php |
|||
$wgDBserver = 'localhost'; |
|||
$wgDBname = ''; |
|||
$wgDBuser = ''; |
|||
$wgDBpassword = ''; |
|||
?> |
|||
</syntaxhighlight> |
|||
=== 网站Logo === |
|||
<syntaxhighlight lang="php"> |
|||
$wgLogos = [ |
|||
'1x' => "$wgResourceBasePath/Libary-4l.png", |
|||
'icon' => "$wgResourceBasePath/Libary-4l.png", |
|||
]; |
|||
$wgFavicon = "$wgResourceBasePath/images/logos/Libary-4l.png"; |
|||
$wgAppleTouchIcon = "$wgResourceBasePath/images/logos/Libary-4l.png"; |
|||
$wgFooterIcons['logo'] = [ |
|||
'yourcustomicon' => [ |
|||
'src' => '/images/logos/Libary-1ll.png ', |
|||
'url' => $wgServer, |
|||
'alt' => 'Logo', |
|||
'height' => '31', |
|||
'width' => '68', |
|||
], |
|||
]; |
|||
</syntaxhighlight> |
|||
=== 移动端皮肤 === |
|||
<syntaxhighlight lang="php"> |
|||
$wgDefaultMobileSkin = 'citizen'; |
|||
</syntaxhighlight> |
|||
=== MediaWiki维护脚本 === |
|||
<syntaxhighlight lang="bash"> |
|||
php maintenance/run.php update.php --quick && \ |
|||
php maintenance/run.php rebuildrecentchanges.php && \ |
|||
php maintenance/run.php rebuildall.php && \ |
|||
php maintenance/run.php rebuildtextindex.php && \ |
|||
php maintenance/run.php refreshLinks.php && \ |
|||
php maintenance/run.php cleanupTitles.php --dry-run |
|||
</syntaxhighlight> |
|||
{{Template:站点帮助文档}} |
|||
== 参见 == |
|||
[[Category:帮助文档]] |
|||
[https://www.mediawiki.org/wiki/Download/zh] |
|||
[https://www.bt.cn/new/download.html] |
|||
[https://zh.wikipedia.org/wiki/Wikipedia:%E9%A6%96%E9%A1%B5] |
|||
[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] |
|||
2026年5月21日 (四) 11:18的最新版本
本页给出通用安装流程,并提供本站当前环境可复用的参数示例。实际部署请以官方文档为准。
参考环境
- 操作系统:Debian 12
- Web 服务器:Nginx
- PHP:8.2(PHP-FPM)
- 数据库:MariaDB 10.11
1. 安装系统依赖
sudo apt update && sudo apt upgrade -y
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
2. 下载并解压 MediaWiki
cd /var/www
wget https://releases.wikimedia.org/mediawiki/1.45/mediawiki-1.45.0.tar.gz
tar -xzvf mediawiki-1.45.0.tar.gz
mv mediawiki-1.45.0 mediawiki
3. 创建数据库与账号
CREATE DATABASE my_wiki CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wikiuser'@'localhost' IDENTIFIED BY '强密码';
GRANT ALL PRIVILEGES ON my_wiki.* TO 'wikiuser'@'localhost';
FLUSH PRIVILEGES;
4. 运行安装向导
完成后将生成的 LocalSettings.php 放入站点根目录。
5. 关键配置示例
$wgScriptPath = '';
$wgArticlePath = '/wiki/$1';
6. 常用安装后维护
php /var/www/mediawiki/maintenance/run.php update.php
php /var/www/mediawiki/maintenance/run.php rebuildrecentchanges.php
php /var/www/mediawiki/maintenance/run.php refreshLinks.php
php /var/www/mediawiki/maintenance/run.php runJobs.php
7. 安全与排错
- 确保
LocalSettings.php权限最小化。 - 上传失败时检查 PHP 上传大小限制与目录权限。
- 页面无法渲染时优先检查 PHP-FPM 与 Nginx 日志。