<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://qingliezhiquan.com/mediawiki/index.php?action=history&amp;feed=atom&amp;title=%E6%80%8E%E6%A0%B7%E4%BF%9D%E6%8A%A4%E4%BD%A0%E7%9A%84_MediaWiki_%E7%AB%99%E7%82%B9%E7%9A%84%E5%AE%89%E5%85%A8%EF%BC%9A%E6%9D%83%E5%B1%9E%E5%BB%BA%E8%AE%AE</id>
	<title>怎样保护你的 MediaWiki 站点的安全：权属建议 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://qingliezhiquan.com/mediawiki/index.php?action=history&amp;feed=atom&amp;title=%E6%80%8E%E6%A0%B7%E4%BF%9D%E6%8A%A4%E4%BD%A0%E7%9A%84_MediaWiki_%E7%AB%99%E7%82%B9%E7%9A%84%E5%AE%89%E5%85%A8%EF%BC%9A%E6%9D%83%E5%B1%9E%E5%BB%BA%E8%AE%AE"/>
	<link rel="alternate" type="text/html" href="https://qingliezhiquan.com/mediawiki/index.php?title=%E6%80%8E%E6%A0%B7%E4%BF%9D%E6%8A%A4%E4%BD%A0%E7%9A%84_MediaWiki_%E7%AB%99%E7%82%B9%E7%9A%84%E5%AE%89%E5%85%A8%EF%BC%9A%E6%9D%83%E5%B1%9E%E5%BB%BA%E8%AE%AE&amp;action=history"/>
	<updated>2026-08-11T09:25:05Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://qingliezhiquan.com/mediawiki/index.php?title=%E6%80%8E%E6%A0%B7%E4%BF%9D%E6%8A%A4%E4%BD%A0%E7%9A%84_MediaWiki_%E7%AB%99%E7%82%B9%E7%9A%84%E5%AE%89%E5%85%A8%EF%BC%9A%E6%9D%83%E5%B1%9E%E5%BB%BA%E8%AE%AE&amp;diff=7937&amp;oldid=prev</id>
		<title>Mwroot: Created page with &quot;; 中文版 by me  上上周，我偶然发现我的网站有一个致命的权限问题，意识到风险后连夜采取安全措施。现在把我学到的保护 MediaWiki 站点的方法，分享给大家。注：本文只讨论 Apache 服务器情况，Nginx 请绕道。  == 思想理念 == * 只把对外要用到的 PHP 入口文件放在 web 根目录，其他一切（配置文件、源码、开发文件、构建工具配置、测试文件、文档等）都应移...&quot;</title>
		<link rel="alternate" type="text/html" href="https://qingliezhiquan.com/mediawiki/index.php?title=%E6%80%8E%E6%A0%B7%E4%BF%9D%E6%8A%A4%E4%BD%A0%E7%9A%84_MediaWiki_%E7%AB%99%E7%82%B9%E7%9A%84%E5%AE%89%E5%85%A8%EF%BC%9A%E6%9D%83%E5%B1%9E%E5%BB%BA%E8%AE%AE&amp;diff=7937&amp;oldid=prev"/>
		<updated>2025-09-29T02:17:34Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;; 中文版 by me  上上周，我偶然发现我的网站有一个致命的权限问题，意识到风险后连夜采取安全措施。现在把我学到的保护 MediaWiki 站点的方法，分享给大家。注：本文只讨论 Apache 服务器情况，Nginx 请绕道。  == 思想理念 == * 只把对外要用到的 PHP 入口文件放在 web 根目录，其他一切（配置文件、源码、开发文件、构建工具配置、测试文件、文档等）都应移...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;; 中文版 by me&lt;br /&gt;
&lt;br /&gt;
上上周，我偶然发现我的网站有一个致命的权限问题，意识到风险后连夜采取安全措施。现在把我学到的保护 MediaWiki 站点的方法，分享给大家。注：本文只讨论 Apache 服务器情况，Nginx 请绕道。&lt;br /&gt;
&lt;br /&gt;
== 思想理念 ==&lt;br /&gt;
* 只把对外要用到的 PHP 入口文件放在 web 根目录，其他一切（配置文件、源码、开发文件、构建工具配置、测试文件、文档等）都应移到 web 根之外，然后用 .htaccess 或 webserver 配置限制访问。&lt;br /&gt;
* 业务逻辑（源码）、静态资源分开放置&lt;br /&gt;
* webserver 仅可读源码，不可写入，不可执行&lt;br /&gt;
* websever 可拥有静态资源&lt;br /&gt;
* 上传目录要禁止代码运行&lt;br /&gt;
* 要阻止对编译产生的 .dot 文件的访问&lt;br /&gt;
* root:root 755 比 root:www-data 750 更开放，后者有时更好，因为对 o 做了限制&lt;br /&gt;
* 任何人、程序、浏览器，访问内容时，都属于某个用户组&lt;br /&gt;
* www-data 既是一个用户名，也是一个用户组名&lt;br /&gt;
* others 指属主、属主之外的任意用户&lt;br /&gt;
* mediawiki.conf sites.conf sites-le-ssl.conf 分开更有逻辑性，不用合并&lt;br /&gt;
* 对源码的各类配置只能是第二道防线，第一道防线应该从 apache 或 nginx 入手&lt;br /&gt;
* 把源码放在 /var/www 本身就是大隐患，会暴露技术栈。源码另存，仅把入口文件放在 /var/www 或 var/www/html，则入口只是 /，更安全&lt;br /&gt;
* Apache 尝试访问某个文件时，该文件的每一个上级路径都要有 x 权限&lt;br /&gt;
* Apache 通过 symbollink 也能访问文件，symbollink 权限由指向的源文件决定&lt;br /&gt;
* .htaccess 本身就是针对当前目录生效的配置，所以 &amp;lt;Directory&amp;gt; 块只能放在 sth.conf&lt;br /&gt;
* 改文件前先备份一个&lt;br /&gt;
&lt;br /&gt;
== 知识清单 ==&lt;br /&gt;
+FollowSymLinks → 允许 Apache 跟随文件系统里的符号链接&lt;br /&gt;
&lt;br /&gt;
-Indexes → 禁止列目录（防止别人看到文件清单）。不会阻止访问目录下的具体文件&lt;br /&gt;
&lt;br /&gt;
AllowOverride All → 开放 .htaccess 管理权限&lt;br /&gt;
&lt;br /&gt;
php_admin_flag engine off → 禁止执行 PHP（防止上传漏洞）&lt;br /&gt;
&lt;br /&gt;
目录的列目录 list 权限是由 r 控制的。&lt;br /&gt;
&lt;br /&gt;
== 根限配置 ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
# change-permissions-and-secure-your-mediawiki.sh&lt;br /&gt;
# 较佳的 MediaWiki 的权限设置脚本，一键解决权限问题，保护你的 MediaWiki 网站的安全&lt;br /&gt;
&lt;br /&gt;
set -euo pipefail&lt;br /&gt;
&lt;br /&gt;
# 建立目录&lt;br /&gt;
SRC=&amp;quot;/home/qlzq/mediawiki&amp;quot; # 刚下载下来的位置&lt;br /&gt;
TARGET=&amp;quot;/home/safe/mediawiki&amp;quot; # 理想的安全的位置&lt;br /&gt;
WEBROOT=&amp;quot;/var/www/html&amp;quot; # 网站的入口&lt;br /&gt;
mkdir -p &amp;quot;$TARGET&amp;quot;&lt;br /&gt;
rm -rf &amp;quot;/var/www/html/*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# 把源码复制进目标地址&lt;br /&gt;
rsync -av --progress &amp;quot;$SRC/&amp;quot; &amp;quot;$TARGET/&amp;quot; &amp;amp;&amp;amp; rm -rf &amp;quot;$SRC/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# 缩减权限&lt;br /&gt;
chown -R root:www-data &amp;quot;$TARGET&amp;quot;&lt;br /&gt;
find &amp;quot;$TARGET&amp;quot; -type d -exec chmod 750 {} \;&lt;br /&gt;
find &amp;quot;$TARGET&amp;quot; -type f -exec chmod 640 {} \;&lt;br /&gt;
&lt;br /&gt;
# 缩减权限，严控维护脚本&lt;br /&gt;
# 未来升级前需临时放宽对脚本的管制&lt;br /&gt;
chown -R root:root &amp;quot;$TARGET/maintenance&amp;quot;&lt;br /&gt;
chmod -R 750 &amp;quot;$TARGET/maintenance&amp;quot;&lt;br /&gt;
find &amp;quot;$TARGET/maintenance&amp;quot; -type f -exec chmod 640 {} \;&lt;br /&gt;
&lt;br /&gt;
# 开放 images 文件夹&lt;br /&gt;
chown -R www-data:www-data &amp;quot;$TARGET/images&amp;quot;&lt;br /&gt;
chmod -R 750 &amp;quot;$TARGET/images&amp;quot;&lt;br /&gt;
find &amp;quot;$TARGET/images&amp;quot; -type f -exec chmod 640 {} \;&lt;br /&gt;
&lt;br /&gt;
# 开放 cache 权限&lt;br /&gt;
# 如果不开放，则会出现 CBD 错误&lt;br /&gt;
chown -R www-data:www-data &amp;quot;$TARGET/cache&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# 开放小文件&lt;br /&gt;
mv &amp;quot;$TARGET/favicon.ico&amp;quot; &amp;quot;$WEBROOT/&amp;quot;&lt;br /&gt;
mv &amp;quot;$TARGET/404.html&amp;quot; &amp;quot;$WEBROOT/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# 软链入口文件&lt;br /&gt;
for f in change-to-some-index.php; do&lt;br /&gt;
    chown root:www-data &amp;quot;$TARGET/$f&amp;quot;&lt;br /&gt;
    chmod 640 &amp;quot;$TARGET/$f&amp;quot;&lt;br /&gt;
    ln -sf &amp;quot;$TARGET/$f&amp;quot; &amp;quot;$WEBROOT/&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# 软链资源文件&lt;br /&gt;
for d in change-to-some-resources; do&lt;br /&gt;
    ln -sfn &amp;quot;$TARGET/$d&amp;quot; &amp;quot;$WEBROOT/&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# 细节维护&lt;br /&gt;
mv &amp;quot;$TARGET/.htaccess&amp;quot; htaccess.bak&lt;br /&gt;
chmod a+x &amp;quot;$TARGET/extensions/SyntaxHighlight_GeSHi/pygments/pygmentize&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;请检查 LocalSettings.php。各 conf 记得改。php maintenance/update.php 一下。确认首页 index.php 能正常访问。&amp;quot;&lt;br /&gt;
echo &amp;quot;Migration complete!&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 文件保护 ==&lt;br /&gt;
要善用 Apache 配置文件，把重要文件保护起来。且上传用的文件夹，要禁止源码被 webserver 写入。&lt;br /&gt;
&lt;br /&gt;
常用的四个定位用关键字为：&lt;br /&gt;
* &amp;lt;Directory&amp;gt; &amp;lt;/Directory&amp;gt;&lt;br /&gt;
* &amp;lt;DirectoryMatch&amp;gt; &amp;lt;/DirectoryMatch&amp;gt;&lt;br /&gt;
* &amp;lt;Files&amp;gt; &amp;lt;/Files&amp;gt;&lt;br /&gt;
* &amp;lt;FilesMatch&amp;gt; &amp;lt;/FilesMatch&amp;gt;&lt;br /&gt;
&lt;br /&gt;
需要保护的文件、文件夹有：&lt;br /&gt;
* 根目录&lt;br /&gt;
* 最重要的配置文件&lt;br /&gt;
* images 目录&lt;br /&gt;
* extensions 目录&lt;br /&gt;
* 其他源码目录&lt;br /&gt;
* .dot 文件&lt;br /&gt;
&lt;br /&gt;
== 其他 ==&lt;br /&gt;
=== 数据库 ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line&amp;gt;&lt;br /&gt;
# /etc/mysql/mariadb.conf.d/50-server.cnf&lt;br /&gt;
skip-networking&lt;br /&gt;
# 或者&lt;br /&gt;
bind-address = 127.0.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 使生效 ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line&amp;gt;&lt;br /&gt;
a2enconf mediawiki-hardening.conf &amp;amp;&amp;amp; apachectl configtest &amp;amp;&amp;amp; systemctl reload apache2&lt;br /&gt;
php update.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Emacs ===&lt;br /&gt;
杜绝 ~ # 文件泄密。&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line&amp;gt;&lt;br /&gt;
(setq make-backup-files nil)   ;; 禁止生成 xxx~&lt;br /&gt;
(setq auto-save-default nil)   ;; 禁止生成 #xxx#&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tar ===&lt;br /&gt;
&amp;lt;code&amp;gt;sudo tar czf xx -C /var/www mediawiki&amp;lt;/code&amp;gt;。&lt;br /&gt;
&lt;br /&gt;
大写 C 代表切换进目录。&lt;br /&gt;
&lt;br /&gt;
小写 c 代表 create。&lt;br /&gt;
&lt;br /&gt;
小写 z 代表 gzip。&lt;br /&gt;
&lt;br /&gt;
小写 f 代表 file。&lt;br /&gt;
&lt;br /&gt;
整条命令意思是进入 /var/www 目录，对 mediawiki 文件夹执行打包操作，形成 xx 文件。&lt;br /&gt;
&lt;br /&gt;
=== ln ===&lt;br /&gt;
&amp;lt;code&amp;gt;ln -sfn 存在 不存在&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
小写 s 代表 symbolic，软链，俗称快捷方式&lt;br /&gt;
&lt;br /&gt;
小写 f 代表 force，目标位置有同名文件则先删除再链接&lt;br /&gt;
&lt;br /&gt;
小写 n 代表 no dereference，不跟随符号链接。如果目标路径已经是一个符号链接，那么 -n 会把它当作普通文件来覆盖，而不会去跟随这个符号链接的指向。 👉 没有 -n 时，假如目标是个符号链接，可能会去覆盖它指向的文件，比较危险。&lt;br /&gt;
&lt;br /&gt;
=== &amp;amp;&amp;amp; ===&lt;br /&gt;
&amp;amp;&amp;amp;：只有当前一个命令返回 0（成功） 时，才会执行后一个命令。&lt;br /&gt;
&lt;br /&gt;
||：只有当前一个命令返回 非 0（失败） 时，才会执行后一个命令。&lt;br /&gt;
&lt;br /&gt;
&amp;amp;：是把命令放到后台执行，并不是条件执行。&lt;br /&gt;
&lt;br /&gt;
=== go-w ===&lt;br /&gt;
&amp;lt;code&amp;gt;chmod -R go-w /var/www/mediawiki&amp;lt;/code&amp;gt; 令该目录无写入权限。&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
; English Version translated by ChatGPT&lt;br /&gt;
&lt;br /&gt;
Two weeks ago I accidentally discovered a critical permission issue on my site. After realizing the risk I spent the night applying fixes. Here I share what I learned about protecting a MediaWiki site.&lt;br /&gt;
Note: this article covers Apache only — Nginx users please consult other resources.&lt;br /&gt;
&lt;br /&gt;
== Philosophy ==&lt;br /&gt;
&lt;br /&gt;
Put only the PHP entry files that must be web-accessible in the web root. Move everything else (config files, source code, dev files, build/tool configs, tests, docs, etc.) outside the web root, and restrict access with .htaccess or the webserver configuration.&lt;br /&gt;
&lt;br /&gt;
Keep application code (source) separate from static assets.&lt;br /&gt;
&lt;br /&gt;
The webserver should be able to read the code but must not be able to write or execute it.&lt;br /&gt;
&lt;br /&gt;
The webserver may own static assets (images, uploaded files).&lt;br /&gt;
&lt;br /&gt;
Upload directories must forbid code execution.&lt;br /&gt;
&lt;br /&gt;
Block access to compiled .dot files.&lt;br /&gt;
&lt;br /&gt;
root:root 755 is more permissive than root:www-data 750; the latter is sometimes preferable because it restricts &amp;quot;others&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Every request (by a person, program, or browser) happens under some user/group.&lt;br /&gt;
&lt;br /&gt;
www-data is both a username and a group name.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;others&amp;quot; means users outside the file owner and owner-group.&lt;br /&gt;
&lt;br /&gt;
Splitting Apache config into mediawiki.conf, sites.conf, sites-le-ssl.conf is cleaner — no need to merge them.&lt;br /&gt;
&lt;br /&gt;
Source-level config is a second line of defense; the first should be Apache (or Nginx) configuration.&lt;br /&gt;
&lt;br /&gt;
Storing source in /var/www is risky because it exposes your stack. Keep source elsewhere and place only the entry files in /var/www or /var/www/html so the site root is just the entry.&lt;br /&gt;
&lt;br /&gt;
When Apache tries to access a file, every parent path must have the x (execute/search) bit.&lt;br /&gt;
&lt;br /&gt;
Apache can follow symlinks; symlink access is governed by the target file permissions.&lt;br /&gt;
&lt;br /&gt;
.htaccess affects its current directory, so &amp;lt;Directory&amp;gt; blocks belong in *.conf files.&lt;br /&gt;
&lt;br /&gt;
Back up any file before editing it.&lt;br /&gt;
&lt;br /&gt;
== Knowledge ==&lt;br /&gt;
&lt;br /&gt;
FollowSymLinks → allow Apache to follow filesystem symlinks.&lt;br /&gt;
&lt;br /&gt;
-Indexes → disable directory listing (prevents exposing file lists). It does not block access to files if their names are known.&lt;br /&gt;
&lt;br /&gt;
AllowOverride All → allow .htaccess to take effect.&lt;br /&gt;
&lt;br /&gt;
php_admin_flag engine off → disable PHP execution (useful to mitigate upload-to-RCE).&lt;br /&gt;
&lt;br /&gt;
Directory listing is controlled by the read (r) bit.&lt;br /&gt;
&lt;br /&gt;
== Permission Example ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
# change-permissions-and-secure-your-mediawiki.sh&lt;br /&gt;
# Recommended MediaWiki permission script — one-shot to fix permissions and harden your site.&lt;br /&gt;
&lt;br /&gt;
set -euo pipefail&lt;br /&gt;
&lt;br /&gt;
paths&lt;br /&gt;
&lt;br /&gt;
SRC=&amp;quot;/home/qlzq/mediawiki&amp;quot; # where you downloaded the source&lt;br /&gt;
TARGET=&amp;quot;/home/safe/mediawiki&amp;quot; # preferred secure location&lt;br /&gt;
WEBROOT=&amp;quot;/var/www/html&amp;quot; # site document root&lt;br /&gt;
mkdir -p &amp;quot;$TARGET&amp;quot;&lt;br /&gt;
rm -rf &amp;quot;$WEBROOT/*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# copy source to target and remove original&lt;br /&gt;
rsync -av --progress &amp;quot;$SRC/&amp;quot; &amp;quot;$TARGET/&amp;quot; &amp;amp;&amp;amp; rm -rf &amp;quot;$SRC/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# tighten permissions&lt;br /&gt;
chown -R root:www-data &amp;quot;$TARGET&amp;quot;&lt;br /&gt;
find &amp;quot;$TARGET&amp;quot; -type d -exec chmod 750 {} ;&lt;br /&gt;
find &amp;quot;$TARGET&amp;quot; -type f -exec chmod 640 {} ;&lt;br /&gt;
&lt;br /&gt;
# restrict maintenance scripts (relax temporarily for upgrades)&lt;br /&gt;
chown -R root:root &amp;quot;$TARGET/maintenance&amp;quot;&lt;br /&gt;
chmod -R 750 &amp;quot;$TARGET/maintenance&amp;quot;&lt;br /&gt;
find &amp;quot;$TARGET/maintenance&amp;quot; -type f -exec chmod 640 {} ;&lt;br /&gt;
&lt;br /&gt;
# allow images to be writable by webserver&lt;br /&gt;
chown -R www-data:www-data &amp;quot;$TARGET/images&amp;quot;&lt;br /&gt;
chmod -R 750 &amp;quot;$TARGET/images&amp;quot;&lt;br /&gt;
find &amp;quot;$TARGET/images&amp;quot; -type f -exec chmod 640 {} ;&lt;br /&gt;
&lt;br /&gt;
# allow cache to be webserver-owned (otherwise CDB errors)&lt;br /&gt;
chown -R www-data:www-data &amp;quot;$TARGET/cache&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# move small static files to webroot&lt;br /&gt;
mv &amp;quot;$TARGET/favicon.ico&amp;quot; &amp;quot;$WEBROOT/&amp;quot;&lt;br /&gt;
mv &amp;quot;$TARGET/404.html&amp;quot; &amp;quot;$WEBROOT/&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# symlink entry files (adjust names)&lt;br /&gt;
for f in change-to-some-index.php; do&lt;br /&gt;
chown root:www-data &amp;quot;$TARGET/$f&amp;quot;&lt;br /&gt;
chmod 640 &amp;quot;$TARGET/$f&amp;quot;&lt;br /&gt;
ln -sf &amp;quot;$TARGET/$f&amp;quot; &amp;quot;$WEBROOT/&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# symlink resource directories (adjust names)&lt;br /&gt;
for d in change-to-some-resources; do&lt;br /&gt;
ln -sfn &amp;quot;$TARGET/$d&amp;quot; &amp;quot;$WEBROOT/&amp;quot;&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
# other details&lt;br /&gt;
mv &amp;quot;$TARGET/.htaccess&amp;quot; htaccess.bak&lt;br /&gt;
chmod a+x &amp;quot;$TARGET/extensions/SyntaxHighlight_GeSHi/pygments/pygmentize&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Check LocalSettings.php and other confs. Run php maintenance/update.php. Confirm index.php loads.&amp;quot;&lt;br /&gt;
echo &amp;quot;Migration complete!&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== File protection ==&lt;br /&gt;
Use Apache configuration to protect important files and ensure upload folders cannot be written to by the webserver as executable code.&lt;br /&gt;
&lt;br /&gt;
Common Apache location blocks:&lt;br /&gt;
* &amp;lt;Directory&amp;gt;...&amp;lt;/Directory&amp;gt;&lt;br /&gt;
* &amp;lt;DirectoryMatch&amp;gt;...&amp;lt;/DirectoryMatch&amp;gt;&lt;br /&gt;
* &amp;lt;Files&amp;gt;...&amp;lt;/Files&amp;gt;&lt;br /&gt;
* &amp;lt;FilesMatch&amp;gt;...&amp;lt;/FilesMatch&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Paths and items to protect:&lt;br /&gt;
* the site root&lt;br /&gt;
* crucial configuration files&lt;br /&gt;
* images directory&lt;br /&gt;
* extensions directory&lt;br /&gt;
* other source directories&lt;br /&gt;
* .dot files&lt;br /&gt;
&lt;br /&gt;
== Other notes ==&lt;br /&gt;
=== Database ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line&amp;gt;&lt;br /&gt;
# /etc/mysql/mariadb.conf.d/50-server.cnf&lt;br /&gt;
skip-networking&lt;br /&gt;
# or&lt;br /&gt;
bind-address = 127.0.0.1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Apply changes ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line&amp;gt;&lt;br /&gt;
a2enconf mediawiki-hardening.conf &amp;amp;&amp;amp; apachectl configtest &amp;amp;&amp;amp; systemctl reload apache2&lt;br /&gt;
php update.php&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Emacs ===&lt;br /&gt;
Prevent leakage of ~ and # backup files:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line&amp;gt;&lt;br /&gt;
(setq make-backup-files nil) ;; disable xxx~ files&lt;br /&gt;
(setq auto-save-default nil) ;; disable #xxx# files&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== tar example ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line&amp;gt;&lt;br /&gt;
sudo tar czf archive.tar.gz -C /var/www mediawiki&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
C change to directory&lt;br /&gt;
&lt;br /&gt;
c=create&lt;br /&gt;
&lt;br /&gt;
z=gzip&lt;br /&gt;
&lt;br /&gt;
f=file&lt;br /&gt;
&lt;br /&gt;
=== ln ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line&amp;gt;&lt;br /&gt;
ln -sfn target linkname&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-s symbolic&lt;br /&gt;
&lt;br /&gt;
-f force&lt;br /&gt;
&lt;br /&gt;
-n no-dereference (do not follow existing symlink)&lt;br /&gt;
&lt;br /&gt;
=== &amp;amp;&amp;amp; ===&lt;br /&gt;
&amp;amp;&amp;amp; : run the next command only if the previous returned 0 (success)&lt;br /&gt;
&lt;br /&gt;
|| : run the next command only if the previous returned non-zero (failure)&lt;br /&gt;
&lt;br /&gt;
&amp;amp; : run command in background (not conditional)&lt;br /&gt;
&lt;br /&gt;
=== go-w ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line&amp;gt;&lt;br /&gt;
chmod -R go-w /var/www/mediawiki&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Make directory non-writable&lt;/div&gt;</summary>
		<author><name>Mwroot</name></author>
	</entry>
</feed>