帮助:MediaWiki 安装:修订间差异
来自陋室
更多操作
删除的内容 添加的内容
修改内容 |
更新和修订环境配置 |
||
| 第1行: | 第1行: | ||
'''注意:''' 此笔记基于 MediaWiki 官方手册及其他网络教程校对,适用于在 Debian Linux 服务器(使用宝塔面板)上安装 MediaWiki。 |
|||
这个页面介绍了本站的 [[mw:Download|MediaWiki]] 的安装笔记. |
|||
== 服务器配置 == |
== 服务器配置 == |
||
'''服务器提供商''': [https://cloud.tencent.com/ 腾讯云]-轻量云(轻量应用服务器) |
'''服务器提供商''': [https://cloud.tencent.com/product/lighthouse 腾讯云]-轻量云(轻量应用服务器) |
||
'''地域和可用区''': 新加坡 | 新加坡一区 |
'''地域和可用区''': 新加坡 | 新加坡一区 |
||
'''实例规格''': |
'''实例规格''': |
||
实例ID = lhins-**** |
|||
* '''CPU''': 2 核 |
|||
实例名称 = sg |
|||
* '''内存''': 2GB |
|||
CPU = 2核 |
|||
* '''系统盘''': SSD 云硬盘 50GB |
|||
内存 = 2GB |
|||
* '''流量包''': 1024GB/月(峰值带宽 30Mbps) |
|||
系统盘 = SSD云硬盘 50GB |
|||
月流量包 = 1024GB(峰值带宽 30Mbps) |
|||
公网IPv4 = 43.163.**** |
|||
'''域名''': |
|||
* www.houjue.digital |
|||
* www.xuepengjia.baby |
|||
'''镜像''': Debian 12.0 64bit |
|||
== 服务器环境 == |
== 服务器环境 == |
||
| 第18行: | 第28行: | ||
=== 操作系统 === |
=== 操作系统 === |
||
'''操作系统''': Debian GNU/Linux 12 (bookworm) |
|||
'''镜像名称''': [https://www.debian.org/distrib/ Debian] |
|||
'''操作系统''': Debian 12.0 64bit |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
cat /etc/os-release |
cat /etc/os-release |
||
sudo apt update |
|||
sudo apt upgrade |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
=== 服务器软件 === |
=== 服务器软件 === |
||
* '''[https://www.bt.cn/new/download.html 宝塔Linux面板]''' : |
* '''[https://www.bt.cn/new/download.html 宝塔Linux面板]''' : 7.9.8 (注:您提供的版本号 11.2.0 与命令中显示的 7.9.8 不一致,请以实际为准) |
||
* '''Apache[httpd]''': 2.4.65 |
|||
* '''MySQL''': 8.0.36 (MediaWiki 最低要求 5.7。大内存机器可考虑 8.0+,官方也推荐 MongoDB) |
|||
* '''PHP''': 8.2.29 (MediaWiki 最低要求 8.1) |
|||
* '''[https://www.phpmyadmin.net/downloads/ phpMyAdmin]''': 5.2(可通过宝塔安装) |
|||
== 安装前准备 == |
|||
在开始安装 MediaWiki 前,请确保系统已更新并安装了必要的依赖。 |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
sudo apt update |
|||
wget -O install_panel.sh https://download.bt.cn/install/install_panel.sh && bash install_panel.sh ed8484bec |
|||
sudo apt upgrade -y |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
== MediaWiki 安装步骤 == |
|||
* '''Apache [https://httpd.apache.org/download.cgi httpd] 2.4.62 (PHP+fpm)''' |
|||
=== 1. 下载 MediaWiki === |
|||
从官方下载页面获取最新的稳定版本(例如 1.44.0)。生产环境建议使用稳定版。 |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
cd /www/wwwroot/ |
|||
which apache2 |
|||
# 使用 wget 下载,请替换为官网最新的稳定版本链接 |
|||
apache2 -v |
|||
wget https://releases.wikimedia.org/mediawiki/1.44/mediawiki-1.44.0.tar.gz |
|||
tar -xzvf mediawiki-1.44.0.tar.gz |
|||
# 解压后得到 mediawiki-1.44.0 目录 |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
=== 2. 创建数据库 === |
|||
* '''[https://dev.mysql.com/downloads/windows/installer/ MySQL 5.7.44]'''(MediaWiki 最低要求 5.7,大内存机器首选 8.0+,官方推荐 MongoDB) |
|||
<syntaxhighlight lang="bash"> |
|||
为 MediaWiki 创建一个专用的数据库和用户。 |
|||
which mysql |
|||
<syntaxhighlight lang="sql"> |
|||
systemctl status mysql |
|||
-- 登录 MySQL,请使用您的 root 密码 |
|||
mysql -u root -p |
|||
-- 在 MySQL 提示符下执行以下命令,请将 '****' 替换为强密码 |
|||
CREATE DATABASE my_wiki; |
|||
CREATE USER 'wikiuser'@'localhost' IDENTIFIED BY '****'; |
|||
GRANT ALL PRIVILEGES ON my_wiki.* TO 'wikiuser'@'localhost' WITH GRANT OPTION; |
|||
FLUSH PRIVILEGES; |
|||
EXIT; |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
'''安全提示''':MySQL/MariaDB 可能会在历史记录文件中记录包含密码的查询命令。请留意并妥善处理 <code>.mysql_history</code> 文件。 |
|||
* '''[https://www.php.net/downloads.php PHP] 8.2.27'''(MediaWiki 最低要求 8.1) |
|||
=== 3. 运行安装脚本 === |
|||
通过浏览器访问您的 MediaWiki 目录,例如:<code>http://您的域名或IP/mediawiki-1.44.0/</code>。这将自动跳转到安装向导 (<code>mw-config/</code>)。 |
|||
'''安装向导关键步骤''': |
|||
# '''环境检查''':确保所有检测通过。 |
|||
# '''数据库设置''':选择 "MySQL" 或 "MariaDB"。填写数据库信息: |
|||
## ''数据库主机'':localhost |
|||
## ''数据库名称'':my_wiki |
|||
## ''数据库用户名'':wikiuser |
|||
## ''数据库密码'':**** |
|||
# '''Wiki 名称''':设置您的 Wiki 站点名称。 |
|||
# '''管理员账户''':创建初始管理员账户(用户名如 <code>WikiSysop</code>)并设置强密码。 |
|||
# '''其他选项''':根据需求选择扩展功能、皮肤等,或保持默认。 |
|||
点击 "安装 MediaWiki"。如果安装成功,页面会提示并允许您下载 <code>LocalSettings.php</code> 文件。 |
|||
=== 4. 完成安装 === |
|||
将下载的 <code>LocalSettings.php</code> 文件上传到您的 MediaWiki 安装目录(例如 <code>/www/wwwroot/mediawiki-1.44.0/</code>)。上传后,Wiki 即可通过 <code>http://您的域名或IP/mediawiki-1.44.0/</code> 访问。 |
|||
'''安全建议''':安装完成后,可以考虑移除 <code>config</code> 目录的世界可写权限: |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
chmod a-w /www/wwwroot/mediawiki-1.44.0/config |
|||
which php |
|||
php -v |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
== 服务器依赖配置 == |
|||
* '''[https://www.phpmyadmin.net/downloads/ phpMyAdmin] 5.2'''(可通过宝塔安装) |
|||
== 服务器依赖 == |
|||
以下是为支持特定 MediaWiki 功能需要安装的依赖。 |
|||
=== php-[[mw:Wikidiff2|wikidiff2]] === |
|||
=== php-wikidiff2 === |
|||
用于提供更好的差异比较显示。 |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
apt-get install php-wikidiff2 |
sudo apt-get install php-wikidiff2 |
||
# 查找扩展所在路径,通常不需要手动在 php.ini 中指定,宝塔面板的 PHP 管理可能已自动启用 |
|||
find /usr/lib/ -name wikidiff2.so |
find /usr/lib/ -name wikidiff2.so |
||
php -m | grep wikidiff2 # 检查是否已加载 |
|||
nano /www/server/php/82/etc/php.ini |
|||
extension=/usr/lib/php/20220829/wikidiff2.so |
|||
php -m | grep wikidiff2 |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
在 <code>LocalSettings.php</code> 中配置: |
|||
<syntaxhighlight lang="php"> |
<syntaxhighlight lang="php"> |
||
$wgDiffEngine = "wikidiff2"; |
$wgDiffEngine = "wikidiff2"; |
||
| 第71行: | 第123行: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
=== php- |
=== php-luasandbox === |
||
用于支持 Scribunto 扩展,运行 Lua 脚本。 |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
sudo apt update |
|||
sudo apt install php-luasandbox -y |
sudo apt install php-luasandbox -y |
||
php -m | grep luasandbox # 检查是否已加载 |
|||
nano /www/server/php/82/etc/php.ini |
|||
extension=/usr/lib/php/20220829/luasandbox.so |
|||
php -m | grep luasandbox |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
在 <code>LocalSettings.php</code> 中启用 Scribunto: |
|||
<syntaxhighlight lang="php"> |
<syntaxhighlight lang="php"> |
||
wfLoadExtension( 'Scribunto' ); |
wfLoadExtension( 'Scribunto' ); |
||
$wgScribuntoEngineConf['luasandbox']['memoryLimit'] = 50 * 1024 * 1024; |
$wgScribuntoEngineConf['luasandbox']['memoryLimit'] = 50 * 1024 * 1024; // 可根据需要调整内存限制 |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=== ffmpeg === |
|||
=== [https://ffmpeg.org/download.html ffmpeg] 6.1(可通过宝塔安装) === |
|||
用于处理视频文件。 |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
sudo apt install ffmpeg -y |
|||
ffmpeg -version |
ffmpeg -version # 验证安装 |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=== |
=== Composer === |
||
PHP 依赖管理工具,某些 MediaWiki 扩展需要。 |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
# 安装 Composer (具体命令请参考 getcomposer.org) |
|||
composer update --no-dev |
|||
curl -sS https://getcomposer.org/installer | php |
|||
mv composer.phar /usr/local/bin/composer |
|||
composer --version # 验证安装 |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
在 MediaWiki 根目录下,可以更新依赖(非开发环境): |
|||
== MediaWiki 插件依赖 == |
|||
=== [[mw:Extension:EasyTimeline|EasyTimeline]] === |
|||
==== [https://ploticus.sourceforge.net/doc/download.html Ploticus] ==== |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
composer update --no-dev |
|||
sudo apt install ploticus |
|||
ploticus -version |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
== 扩展特定依赖 == |
|||
==== [https://www.perl.org/get.html perl] ==== |
|||
=== EasyTimeline 扩展 === |
|||
用于生成时间线图表。 |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
sudo apt |
sudo apt install ploticus perl -y |
||
sudo apt install perl |
|||
perl -v |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
在 <code>LocalSettings.php</code> 中配置: |
|||
<syntaxhighlight lang="php"> |
<syntaxhighlight lang="php"> |
||
$wgTimelinePloticusCommand = '/usr/bin/ploticus'; |
$wgTimelinePloticusCommand = '/usr/bin/ploticus'; |
||
$wgTimelinePerlCommand = "/usr/bin/perl"; |
$wgTimelinePerlCommand = "/usr/bin/perl"; |
||
$wgTimelineFontDirectory = "/usr/share/fonts/truetype/freefont"; |
$wgTimelineFontDirectory = "/usr/share/fonts/truetype/freefont"; // 字体路径请根据系统实际情况调整 |
||
$wgTimelineFontFile = 'ascii'; |
$wgTimelineFontFile = 'ascii'; // 字体文件名请根据系统实际情况调整 |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=== |
=== Score 扩展 === |
||
用于渲染乐谱。 |
|||
==== [https://lilypond.org/ LilyPond] ==== |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
sudo apt install lilypond ghostscript fluidsynth imagemagick lame -y |
|||
sudo apt update |
|||
sudo apt install lilypond |
|||
lilypond --version |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
在 <code>LocalSettings.php</code> 中配置: |
|||
==== [https://www.ghostscript.com/releases/index.html Ghostscript] ==== |
|||
<syntaxhighlight lang="bash"> |
|||
sudo apt update |
|||
sudo apt install ghostscript |
|||
gs --version |
|||
</syntaxhighlight> |
|||
==== php-ImageMagick ==== |
|||
==== [https://www.fluidsynth.org/download/ FluidSynth] ==== |
|||
<syntaxhighlight lang="bash"> |
|||
sudo apt update |
|||
sudo apt install fluidsynth |
|||
fluidsynth --version |
|||
</syntaxhighlight> |
|||
<syntaxhighlight lang="php"> |
<syntaxhighlight lang="php"> |
||
$wgScoreTrim = true; |
$wgScoreTrim = true; |
||
$wgImageMagickConvertCommand = '/usr/bin/convert'; |
$wgImageMagickConvertCommand = '/usr/bin/convert'; |
||
$wgScoreSafeMode = false; |
$wgScoreSafeMode = false; // 注意:关闭安全模式可能有安全风险,请确保系统安全 |
||
$wgScoreLame = '/usr/bin/lame'; |
$wgScoreLame = '/usr/bin/lame'; |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=== |
=== PdfHandler 扩展 === |
||
用于预览 PDF 文件。 |
|||
==== Ghostscript ==== |
|||
==== php-imagemagick ==== |
|||
==== [https://pypi.org/project/poppler-utils/#files poppler-utils] ==== |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
sudo apt install poppler-utils -y # 提供 pdftotext, pdfinfo 等工具 |
|||
sudo apt update |
|||
sudo apt install poppler-utils |
|||
pdftotext -v |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
在 <code>LocalSettings.php</code> 中配置(Ghostscript 和 ImageMagick 已在前面安装): |
|||
<syntaxhighlight lang="php"> |
<syntaxhighlight lang="php"> |
||
$wgPdfProcessor = '/usr/bin/gs'; |
$wgPdfProcessor = '/usr/bin/gs'; |
||
$wgPdfPostProcessor = $wgImageMagickConvertCommand; |
$wgPdfPostProcessor = $wgImageMagickConvertCommand; // 假设 $wgImageMagickConvertCommand 已定义为 '/usr/bin/convert' |
||
$wgPdfInfo = '/usr/bin/pdfinfo'; |
$wgPdfInfo = '/usr/bin/pdfinfo'; |
||
$wgPdftoText = '/usr/bin/pdftotext'; |
$wgPdftoText = '/usr/bin/pdftotext'; |
||
| 第185行: | 第198行: | ||
== 服务器配置 == |
== 服务器配置 == |
||
=== Apache |
=== Apache 与 HTTPS === |
||
通过宝塔面板或手动配置,确保站点启用了 HTTPS 并设置了重定向。 |
|||
* '''禁用''' 防跨站攻击 (open_basedir) |
|||
* '''启用''' HTTPS 防窜站 |
|||
* '''禁用''' TLS 1.0 和 1.1 |
|||
'''伪静态配置''' |
|||
'''伪静态配置(.htaccess)''' |
|||
将以下规则放入 <code>/www/wwwroot/mediawiki-1.44.0/.htaccess</code> 文件,以实现短链接(如 <code>/w/PageTitle</code>)和 HTTPS 强制跳转。 |
|||
<syntaxhighlight lang="apache"> |
<syntaxhighlight lang="apache"> |
||
RewriteEngine On |
RewriteEngine On |
||
# 强制 HTTPS |
|||
RewriteCond %{HTTPS} off |
RewriteCond %{HTTPS} off |
||
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] |
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] |
||
# MediaWiki 短链接规则 |
|||
RewriteCond %{REQUEST_URI} !\.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|less)$ [NC] |
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} !^/load\.php [NC] |
||
RewriteCond %{REQUEST_URI} !^/api.php [NC] |
RewriteCond %{REQUEST_URI} !^/api\.php [NC] |
||
RewriteRule ^w/(.*)$ /index.php?title=$1 [L,QSA] |
RewriteRule ^w/(.*)$ /index.php?title=$1 [L,QSA] |
||
# 前端控制器模式,将所有其他请求路由到 index.php |
|||
RewriteCond %{REQUEST_FILENAME} !-f |
RewriteCond %{REQUEST_FILENAME} !-f |
||
RewriteCond %{REQUEST_FILENAME} !-d |
RewriteCond %{REQUEST_FILENAME} !-d |
||
| 第206行: | 第221行: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
在 <code>LocalSettings.php</code> 中配置相应的动作路径和文章路径,以配合短链接: |
|||
<syntaxhighlight lang="php"> |
<syntaxhighlight lang="php"> |
||
$wgScriptPath = "/mediawiki-1.44.0"; // MediaWiki 的安装路径,根据实际情况修改 |
|||
wfLoadExtension( 'UrlShortener' ); |
|||
$wgArticlePath = "/w/$1"; // 设置文章短链接路径 |
|||
$wgUrlShortenerTemplate = '/r/$1'; |
|||
$wgUrlShortenerServer = "false"; |
|||
// 以下代码为各种动作定义短链接路径(需与 .htaccess 规则配合) |
|||
$wgUrlShortenerEnableQrCode = true; |
|||
$wgUrlShortenerQrCodeShortenLimit = 200; |
|||
$actions = [ |
$actions = [ |
||
'view', 'edit', 'watch', 'unwatch', 'delete', 'revert', 'rollback', |
|||
'view', |
|||
'protect', 'unprotect', 'markpatrolled', 'render', 'submit', 'history', |
|||
'edit', |
|||
' |
'purge', 'info' |
||
'unwatch', |
|||
'delete', |
|||
'revert', |
|||
'rollback', |
|||
'protect', |
|||
'unprotect', |
|||
'markpatrolled', |
|||
'render', |
|||
'submit', |
|||
'history', |
|||
'purge', |
|||
'info', |
|||
]; |
]; |
||
foreach ($actions as $action) { |
foreach ($actions as $action) { |
||
$wgActionPaths[$action] = "/w/$action/$1"; |
$wgActionPaths[$action] = "/w/$action/$1"; |
||
} |
} |
||
// 确保 'view' 动作使用上面设置的 $wgArticlePath |
|||
$wgActionPaths['view'] = "/w/$1"; |
|||
$wgActionPaths['view'] = $wgArticlePath; |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
=== |
=== 安全配置 === |
||
=== Apache 安全配置 === |
|||
'''保护上传目录''':在 Apache 虚拟主机配置或 <code>.htaccess</code> 中,对上传目录(例如 <code>images/</code>)添加限制,禁止执行 PHP 等脚本。 |
|||
<syntaxhighlight lang="apache"> |
<syntaxhighlight lang="apache"> |
||
<Directory /www/wwwroot/ |
<Directory "/www/wwwroot/mediawiki-1.44.0/images"> |
||
# 禁止执行特定脚本类型 |
|||
Options -ExecCGI -Indexes |
|||
AllowOverride None |
|||
<FilesMatch "\.(php|php5|pl|py|jsp|asp|htm|html|cgi|sh)$"> |
<FilesMatch "\.(php|php5|pl|py|jsp|asp|htm|html|cgi|sh)$"> |
||
Require all denied |
Require all denied |
||
</FilesMatch> |
</FilesMatch> |
||
# 设置安全头 |
|||
Header always set X-Content-Type-Options "nosniff" |
Header always set X-Content-Type-Options "nosniff" |
||
</syntaxhighlight> |
|||
</Directory> |
|||
设置目录权限: |
|||
<syntaxhighlight lang="bash"> |
|||
chown -R www-data:www-data /www/wwwroot/mediawiki-1.44.0/images # 确保 Web 服务器用户有写权限 |
|||
chmod 755 /www/wwwroot/mediawiki-1.44.0/images |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
=== MySQL |
=== MySQL 配置建议 === |
||
* 将所有表转换为 '''InnoDB''' 存储引擎。 |
|||
'''官方建议''': |
|||
* 使用 <code>utf8mb4</code> 字符集以支持更广泛的 Unicode 字符。 |
|||
=== PHP 配置 === |
|||
* 将所有表转为 '''InnoDB''' |
|||
* 将所有表转为 <code>utf8mb4</code> |
|||
=== PHP相关 === |
|||
'''需要启用的插件'''(部分插件已默认启用) |
|||
'''需要启用的扩展''': |
|||
通过宝塔面板的 PHP 管理界面或编辑 <code>php.ini</code>,确保以下扩展已启用(大部分可能已默认安装或启用): |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
php -m # 查看已加载的扩展 |
|||
php -m |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
核心扩展包括:<code>gd</code>, <code>intl</code>, <code>xml</code>, <code>mbstring</code>, <code>pdo_mysql</code>, <code>json</code>, <code>fileinfo</code>, <code>curl</code>, <code>zip</code> 等。根据前面安装的依赖,还需确保 <code>wikidiff2</code>, <code>luasandbox</code>, <code>imagick</code> 等扩展已加载。 |
|||
'''需要解除禁用的函数'''(某些扩展如 Score 需要): |
|||
<syntaxhighlight lang="php"> |
|||
在宝塔面板的 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 |
|||
* <code>proc_open</code> |
|||
</syntaxhighlight> |
|||
* <code>popen</code> |
|||
* <code>putenv</code> |
|||
调整 PHP 限制以适应文件上传和处理: |
|||
'''需要解除禁用的函数''' |
|||
在 <code>php.ini</code> 中调整(具体值根据需求设定): |
|||
<syntaxhighlight lang=" |
<syntaxhighlight lang="ini"> |
||
memory_limit = 128M |
|||
proc_open |
|||
upload_max_filesize = 20M |
|||
popen |
|||
post_max_size = 20M |
|||
putenv |
|||
max_execution_time = 60 |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
== 站点配置 == |
== 站点配置 (LocalSettings.php) == |
||
=== 数据库信息安全 === |
=== 数据库信息安全 === |
||
<code>LocalSettings.php</code> |
考虑将数据库凭证从 <code>LocalSettings.php</code> 中分离。 |
||
1. 创建单独的配置文件,例如 <code>/www/wwwroot/lib.php</code>: |
|||
<syntaxhighlight lang="php"> |
|||
include('/wwwroot/lib.php'); |
|||
</syntaxhighlight> |
|||
<code>lib.php</code> |
|||
<syntaxhighlight lang="php"> |
<syntaxhighlight lang="php"> |
||
<?php |
<?php |
||
$wgDBserver = 'localhost'; |
$wgDBserver = 'localhost'; |
||
$wgDBname = ''; |
$wgDBname = 'my_wiki'; |
||
$wgDBuser = ''; |
$wgDBuser = 'wikiuser'; |
||
$wgDBpassword = ''; |
$wgDBpassword = '****'; // 替换为实际密码 |
||
?> |
?> |
||
</syntaxhighlight> |
|||
2. 在 <code>LocalSettings.php</code> 开头包含此文件: |
|||
<syntaxhighlight lang="php"> |
|||
include('/www/wwwroot/lib.php'); |
|||
// 注意:确保 lib.php 文件权限严格(如 600),且不在 Web 可访问目录下。 |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
=== 网站 Logo === |
=== 网站 Logo 与图标 === |
||
<syntaxhighlight lang="php"> |
<syntaxhighlight lang="php"> |
||
$wgLogos = [ |
$wgLogos = [ |
||
'1x' => "$wgResourceBasePath/resources/assets/logo.png", // 替换为您的 logo 路径 |
|||
'icon' => "$wgResourceBasePath/resources/assets/icon.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', |
|||
], |
|||
]; |
]; |
||
$wgFavicon = "$wgResourceBasePath/resources/assets/favicon.ico"; // 替换为您的 favicon 路径 |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
=== 移动端皮肤 === |
=== 移动端皮肤 === |
||
如果安装了 Citizen 等皮肤,可以将其设为移动端默认: |
|||
<syntaxhighlight lang="php"> |
<syntaxhighlight lang="php"> |
||
$wgDefaultMobileSkin = 'citizen'; |
$wgDefaultMobileSkin = 'citizen'; |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
== MediaWiki 维护 == |
|||
定期运行维护脚本以保持 Wiki 健康运行。 |
|||
<syntaxhighlight lang="bash"> |
<syntaxhighlight lang="bash"> |
||
# 进入 MediaWiki 安装目录 |
|||
php maintenance/run.php update.php --quick && \ |
|||
cd /www/wwwroot/mediawiki-1.44.0 |
|||
php maintenance/run.php rebuildrecentchanges.php && \ |
|||
php maintenance/run.php rebuildall.php && \ |
|||
# 运行数据库更新(扩展更新后尤其需要) |
|||
php maintenance/run.php rebuildtextindex.php && \ |
|||
php maintenance/run.php |
php maintenance/run.php update.php --quick |
||
php maintenance/run.php cleanupTitles.php --dry-run |
|||
# 重建最近更改 |
|||
php maintenance/run.php rebuildrecentchanges.php |
|||
# 重构链接表 |
|||
php maintenance/run.php refreshLinks.php |
|||
# 其他可选维护任务 |
|||
# php maintenance/run.php cleanupTitles.php --dry-run # 先干跑检查,确认无误后再移除 --dry-run 执行 |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
可以将这些命令添加到 crontab 中定期执行。 |
|||
== 故障排除 == |
|||
* '''安装时无法写入 <code>config</code> 目录''':检查目录权限和 SELinux 设置(尤其在 CentOS/RHEL 系系统上)。可能需要执行: |
|||
<syntaxhighlight lang="bash"> |
|||
# 临时调整权限(安装后应改回) |
|||
chmod 755 /www/wwwroot/mediawiki-1.44.0/config |
|||
# 如果使用 SELinux,可能需要调整上下文 |
|||
semanage fcontext -a -t httpd_sys_rw_content_t "/www/wwwroot/mediawiki-1.44.0/config(/.*)?" |
|||
restorecon -R -v /www/wwwroot/mediawiki-1.44.0/config |
|||
</syntaxhighlight> |
|||
* '''页面显示 Wiki 标记(WikiText)而非渲染后的内容''':检查 PHP 解析是否正常,以及 <code>LocalSettings.php</code> 是否存在且可读。 |
|||
* '''上传文件失败''':检查 <code>images/</code> 目录权限、PHP 文件上传大小限制 (<code>upload_max_filesize</code>, <code>post_max_size</code>) 以及 Apache 配置。 |
|||
{{Template:站点帮助文档}} |
{{Template:站点帮助文档}} |
||