打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。
XP-jia留言 | 贡献2025年3月2日 (日) 19:10的版本 (修改内容)

这个页面介绍了本站的 MediaWiki 的安装笔记.

服务器配置

服务器提供商: 腾讯云-轻量云(轻量应用服务器)

地域和可用区: 新加坡 | 新加坡一区

实例规格:

  • CPU: 2 核
  • 内存: 2GB
  • 系统盘: SSD 云硬盘 50GB
  • 流量包: 1024GB/月(峰值带宽 30Mbps)

服务器环境

操作系统

镜像名称: Debian

操作系统: Debian 12.0 64bit

cat /etc/os-release
sudo apt update
sudo apt upgrade

服务器软件

wget -O install_panel.sh https://download.bt.cn/install/install_panel.sh && bash install_panel.sh ed8484bec
  • Apache httpd 2.4.62 (PHP+fpm)
which apache2
apache2 -v
  • MySQL 5.7.44(MediaWiki 最低要求 5.7,大内存机器首选 8.0+,官方推荐 MongoDB)
which mysql
systemctl status mysql
  • PHP 8.2.27(MediaWiki 最低要求 8.1)
which php
php -v

服务器依赖

apt-get install php-wikidiff2
find /usr/lib/ -name wikidiff2.so
nano /www/server/php/82/etc/php.ini
extension=/usr/lib/php/20220829/wikidiff2.so
php -m | grep wikidiff2
$wgDiffEngine = "wikidiff2";
$wgDiff3 = "/usr/bin/diff3";
sudo apt update
sudo apt install php-luasandbox -y
find /usr/lib/php/ -name "luasandbox.so"
nano /www/server/php/82/etc/php.ini
extension=/usr/lib/php/20220829/luasandbox.so
php -m | grep luasandbox
wfLoadExtension( 'Scribunto' );
$wgScribuntoEngineConf['luasandbox']['memoryLimit'] = 50 * 1024 * 1024;

ffmpeg 6.1(可通过宝塔安装)

which ffmpeg
ffmpeg -version
composer update --no-dev

MediaWiki 插件依赖

sudo apt update
sudo apt install ploticus
ploticus -version
sudo apt update
sudo apt install perl
perl -v
$wgTimelinePloticusCommand = '/usr/bin/ploticus';
$wgTimelinePerlCommand = "/usr/bin/perl";
$wgTimelineFontDirectory = "/usr/share/fonts/truetype/freefont";
$wgTimelineFontFile = 'ascii';
sudo apt update
sudo apt install lilypond
lilypond --version
sudo apt update
sudo apt install ghostscript
gs --version

php-ImageMagick

sudo apt update
sudo apt install fluidsynth
fluidsynth --version
$wgScoreTrim = true;
$wgImageMagickConvertCommand = '/usr/bin/convert';
$wgScoreSafeMode = false;
$wgScoreLame = '/usr/bin/lame';

Ghostscript

php-imagemagick

sudo apt update
sudo apt install poppler-utils
pdftotext -v
$wgPdfProcessor = '/usr/bin/gs';
$wgPdfPostProcessor = $wgImageMagickConvertCommand;
$wgPdfInfo = '/usr/bin/pdfinfo';
$wgPdftoText = '/usr/bin/pdftotext';

服务器配置

Apache 相关

  • 禁用 防跨站攻击 (open_basedir)
  • 启用 HTTPS 防窜站
  • 禁用 TLS 1.0 和 1.1

伪静态配置

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]
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'];

SSL

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>

MySQL 相关

官方建议:

  • 将所有表转为 InnoDB
  • 将所有表转为 utf8mb4

PHP相关

需要启用的插件(部分插件已默认启用)

php -m
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

需要解除禁用的函数

proc_open
popen
putenv

站点配置

数据库信息安全

LocalSettings.php

include('/wwwroot/lib.php');

lib.php

<?php
$wgDBserver = 'localhost';
$wgDBname = '';
$wgDBuser = '';
$wgDBpassword = '';
?>
$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', 
    ],
];

移动端皮肤

$wgDefaultMobileSkin = 'citizen';

MediaWiki 维护脚本

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