說明:MediaWiki安裝指南

XP-jia​(對話 | 貢獻)2025年2月11日 (二) 19:06的修訂 (完成)

這個頁面介紹了本站的 MediaWiki 的安裝筆記.

伺服器配置

伺服器提供商: 騰訊雲-輕量雲(輕量應用伺服器)

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

實例規格:

  • CPU: 2核
  • 內存: 2GB
  • 系統盤: SSD雲硬盤 50GB
  • 流量包: 1024GB/月(峰值帶寬 30Mbps)

伺服器環境

作業系統

鏡像名稱: Debian

作業系統: Debian 12.0 64bit

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

伺服器軟件

  • 寶塔Linux面板: 正式版9.4.0
wget -O install_panel.sh https://download.bt.cn/install/install_panel.sh && bash install_panel.sh ed8484bec
  • Apache 2.4.62 (PHP+fpm)
which apache2
apache2 -v
  • MySQL 5.7.44(MediaWiki最低要求5.7,官方推薦MongoDB)
which mysql
systemctl status mysql
  • PHP 8.2.27(MediaWiki最低要求8.1)
which php
php -v
  • phpMyAdmin 5.2(可通過寶塔安裝)
  • ffmpeg 6.1(可通過寶塔安裝)
which ffmpeg
ffmpeg -version

依賴軟件安裝

php-wikidiff2

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";

LilyPond

sudo apt update
sudo apt install lilypond
lilypond --version
wfLoadExtension( 'Score' );
$wgScoreTrim = true;
$wgImageMagickConvertCommand = '/usr/bin/convert';
$wgScoreSafeMode = false;

Ghostscript

sudo apt update
sudo apt install ghostscript
gs --version

FluidSynth

sudo apt update
sudo apt install fluidsynth
fluidsynth --version

LAME

sudo apt update
sudo apt install lame
lame --version
$wgScoreLame = '/usr/bin/lame';

php-luasandbox

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;

Composer

composer update --no-dev

伺服器配置

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('/www/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

參見

[1] [2] [3] [4] [5] [6] [7] [8]