“FAQ:MediaWiki”的版本间差异

来自Wikioe
跳到导航 跳到搜索
 
(未显示同一用户的2个中间版本)
第5行: 第5行:


== '''open_basedir 问题''' ==
== '''open_basedir 问题''' ==
  <span style="color: red; font-size: 110%">'''Warning: is_executable(): open_basedir restriction in effect.''' File(/bin/bash) is not within the allowed path(s): (/www/wwwroot/wiki.eijux.com/:/tmp/) in /www/wwwroot/wiki.eijux.com/includes/shell/Command.php on line 311</span>
  <span style="color: red; font-size: 110%">Warning: is_executable(): '''open_basedir''' restriction in effect. '''File(/bin/bash)''' is not within the allowed path(s): (/www/wwwroot/wiki.eijux.com/:/tmp/) in /www/wwwroot/wiki.eijux.com/includes/shell/Command.php on line 311</span>
   
   
     [[File:MediaWiki:open_basedir问题.png|800px]]
     [[File:MediaWiki:open_basedir问题.png|800px]]
第19行: 第19行:
3、当文件在指定的目录树之外时 PHP 将拒绝打开它。
3、当文件在指定的目录树之外时 PHP 将拒绝打开它。
</blockquote>
</blockquote>
:::* '''open_basedir''' 指定的限制是'''路径前缀,而非目录名'''。(如:设置“/dir/user”,则“/dir/user”和“/dir/user1”都是可以访问的)。
:::** 所以如果要将访问限制在仅为指定的目录,应用斜线结束路径名(如:“/dir/user/”)。
:::* '''open_basedir''' 若配置为 Linux 根目录“<span style="color: blue">'''/'''</span>”,则一定不会再报错,但是“'''防止跨站攻击'''”也就没啥意义了。




第36行: 第39行:
</syntaxhighlight>
</syntaxhighlight>
##* 配置文件:位于“<span style="color: green">/www/server/panel/vhost/openlitespeed/detail/wiki.eijux.com.conf</span>”。
##* 配置文件:位于“<span style="color: green">/www/server/panel/vhost/openlitespeed/detail/wiki.eijux.com.conf</span>”。
# <span style="color: blue">'''配置“open_basedir”'''</span>:通过编辑“<span style="color: blue; font-size: 120%">'''.user.ini'''</span>”文件,添加必要的目录树:
# <span style="color: blue">'''配置“open_basedir”'''</span>:修改“<span style="color: blue">'''.user.ini'''</span>”文件,添加必要的目录树。步骤:
#: <syntaxhighlight lang="PHP" line highlight="">
## 根据错误信息,查找需要添加的目录;
open_basedir=/www/wwwroot/wiki.eijux.com/:/tmp/
##: 如上:“File(/bin/bash) 不在被允许的路径中”
</syntaxhighlight>
##* 也可以根据“服务器上的站点错误日志<ref>位于:“/www/wwwlogs/wiki.eijux.com.error.log”。</ref>”。
#* '''.user.ini''' 文件:开启“防止跨站攻击”之后自动创建,位于项目根目录,用于配置“open_basedir”。
## '''确认“待添加目录”的“实际路径”''':因为目录可能是 '''Symlink'''(符号链接);
#* '''open_basedir'''指定的限制是'''路径前缀,而非目录名'''(如:设置“/dir/user”,则“/dir/user”和“/dir/user1”都是可以访问的)。
##: 如上:“/bin/bash”就是指向“/usr/bin/bash”的符号链接。
#** 所以如果要将访问限制在仅为指定的目录,应用斜线结束路径名(如:“/dir/user/”)。
## 开启站点的“防止跨站攻击”,并配置“<big>'''.user.ini'''</big>”文件:
#* 添加 Linux 根目录“<span style="color: blue">'''/'''</span>”,则一定不会再报错,但是“防止跨站攻击”也就没啥意义了。
##: <span style="color: blue">'''<syntaxhighlight lang="PHP" line highlight="">
#**<s>【通过错误信息定位需要的目录实在麻烦!】</s>
open_basedir=/www/wwwroot/wiki.eijux.com/:/tmp/:/usr/bin/bash
</syntaxhighlight>'''</span>
## 访问站点的文章页面,以确定不再有“open_basedir 问题”。
:::<span style="color: blue; font-size: 120%">【2022/08/23 17:47:44 验证】</span>




=== '''如何明确需要的目录树?''' ===
  <span style="color: blue; font-size: 150%">'''.user.ini'''</span>”:用于配置“'''open_basedir'''”
----
  之前一直想要通过“界面上的错误信息”来找到需要配置到“<span style="color: green">'''open_basedir'''</span>”的“目录树”。
   
   
  但是,突然想到:“<span style="color: blue">'''服务器的错误日志'''</span>”提供的信息是否更详细、明确?
  1、开启“防止跨站攻击”后自动生成。(<span style="color: blue">'''位于项目根目录'''</span>
 
<big>'''步骤:'''</big>
# 从服务器上获取站点错误日志:“<span style="color: blue">'''wiki.eijux.com.error.log'''</span>”;
#* 位于:“/www/wwwlogs/”。
# 在服务器中利用“open_basedir”筛选错误信息:
#: <syntaxhighlight lang="bash" highlight="">
2022/08/23 15:20:27 [error] 1098830#0: *11213 FastCGI sent in stderr: "PHP message: PHP Warning:  file_exists(): open_basedir restriction in effect. File(/bin/bash) is not within the allowed path(s): (/www/wwwroot/wiki.eijux.com/:/tmp/) in /www/wwwroot/wiki.eijux.com/includes/shell/CommandFactory.php on line 119PHP message: PHP Warning:  file_exists(): open_basedir restriction in effect. File(/bin/bash) is not within the allowed path(s): (/www/wwwroot/wiki.eijux.com/:/tmp/) in /www/wwwroot/wiki.eijux.com/includes/shell/CommandFactory.php on line 119PHP message: PHP Warning:  file_exists(): open_basedir restriction in effect. File(/bin/bash) is not within the allowed path(s): (/www/wwwroot/wiki.eijux.com/:/tmp/) in /www/wwwroot/wiki.eijux.com/includes/shell/CommandFactory.php on line 119PHP message: PHP Warning:  file_exists(): open_basedir restriction in effect. File(/bin/bash) is not within the allowed path(s): (/www/wwwroot/wiki.eijux.com/:/tmp/) in /www/wwwroot/wiki.eijux.com/includes/shell/CommandFactory.php on line 119" while reading response header from upstream, client: 118.112.56.144, server: wiki.eijux.com, request: "GET /%E7%AB%99%E7%82%B9%E6%97%A5%E5%BF%97 HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-cgi-74.sock:", host: "wiki.eijux.com", referrer: "http://wiki.eijux.com/%E9%A6%96%E9%A1%B5"
</syntaxhighlight>
#: 可以看出,此处错误信息与“界面上的错误信息”完全不同:'''File(/bin/bash) 不在被允许的路径中。'''
#:: <syntaxhighlight lang="bash" highlight="">
PHP message: PHP Warning:  file_exists(): open_basedir restriction in effect. File(/bin/bash) is not within the allowed path(s): (/www/wwwroot/wiki.eijux.com/:/tmp/) in /www/wwwroot/wiki.eijux.com/includes/shell/CommandFactory.php on line 119PHP
</syntaxhighlight>
# '''确认“待添加目录”的“实际路径”''':因为目录可能是 '''Symlink'''(符号链接);
#: 如:上述“'''/bin/bash'''”就是指向“'''/usr/bin/bash'''”的符号链接。
# 开启站点的“防止跨站攻击”,并配置“<big>'''.user.ini'''</big>”文件:
#: <syntaxhighlight lang="PHP" line highlight="">
open_basedir=/www/wwwroot/eijux.com/:/tmp/:/usr/bin/bash
</syntaxhighlight>
# 访问站点的文章页面,以确定不再有“open_basedir 问题”。
<span style="color: blue; font-size: 120%">【2022/08/23 17:47:44 解决】</span>
 
 
“<span style="color: blue; font-size: 150%">'''.user.ini'''</span>”:
   
   
  1、开启“防止跨站攻击”后自动生成,关闭“防止跨站攻击”自动删除;
  2、关闭“防止跨站攻击”自动删除;
   
   
  2、不能被上传覆盖,只能在服务器修改;
  3、不能被上传覆盖,只能在服务器修改;
   
   
   
   
第85行: 第66行:
  [[File:宝塔面板:修改“.user.ini”.png|800px]]
  [[File:宝塔面板:修改“.user.ini”.png|800px]]


== 无法生成avg缩略图 ==
== 页面显示无格式 ==
'''如果要使用第三方的converter,参见[https://www.mediawiki.org/wiki/Manual:Installing_third-party_tools#Image_thumbnailing Image thumbnailing页面]'''
访问所有页面都只有文字,没有格式。如图:
* '''描述:'''
上传'''<code>.svg</code>'''文件过后,页面中提示“生成缩略图出错:无法创建临时缩略图文件”,在“特殊页面:文件列表”中查看文件时:
    [[File:MediaWiki:“$wgScriptPath”设置导致页面显示格式不对.png|800px]]
'''<code>Warning: symlink() has been disabled for security reasons in /www/wwwroot/wiki.eijux.com/includes/media/SvgHandler.php on line 280</code>'''
 
*'''处理:'''
'''解决:'''
默认安装的PHP一些函数是没有默认开启的。
# 检查本地网络环境;
我们需要的函数是'''<code>symlink()</code>''',则用在PHP的禁用函数中删除该函数即可。
# 检查系统配置文件(“'''LocalSettings.php'''”)中的“<span style="color: blue; font-size: 120%">'''$wgScriptPath'''</span><ref>[[手册:LocalSettings#$wgScriptPath]]</ref>”配置。
----
#* “'''$wgScriptPath'''”的配置与 MediaWiki 安装路径不匹配,会导致无法获取 MediaWiki 的各个脚本,从而出现上述情况。
* '''描述:'''
 
生成缩略图处提示:'''<code>sh: convert: command not found</code>''',PHP错误信息为'''<code>Warning: is_executable(): open_basedir restriction in effect. File(/bin/bash) is not within the allowed path(s): (/www/wwwroot/wiki.eijux.com/:/tmp/) in /www/wwwroot/wiki.eijux.com/includes/shell/Command.php on line 311</code>'''
== '''SVG'''<ref>参考:[https://www.mediawiki.org/wiki/Manual:Image_administration/zh#SVG Manual:Image administration#SVG]</ref> 缩略图问题 ==
* '''处理:'''
初次上传 svg(矢量图)时,遇到了几个问题,基本上都是由于配置不完全导致。
先考虑是PHP配置的问题,
 
<pre>
=== “无法创建临时缩略图文件” ===
PHP错误'''require(): open_basedir restriction in effect”''',即访问脚本不在'''<code>open_basedir</code>'''的限定目录里面,'''<code>open_basedir</code>'''的作用是将php所能打开的文件限制在指定的目录或文件。<br/>
上传“<span style="color: blue; font-size: 150%">'''.svg'''</span>”文件后:
</pre>
修改PHP配置文件<code>PHP.ini</code>的<code>open_basedir</code>之后错误依旧,而后一直都盯着<code>open_basedir</code>打转。兜兜转转许久才注意到<code>sh: convert: command not found</code>的提示,想到可能没有配置Svg Converter,从而进一步发现MediaWiki没有默认安装Converter。最后在[https://www.mediawiki.org/wiki/Manual:Image_administration/zh#SVG | 官网手册SVG节]了解到支持信息,相关的Converter("ImageMagick", "ImagickExt", "sodipodi", "inkscape", "batik", "rsvg", and "imgserv")均需单独安装。相较之下,选用了[https://www.mediawiki.org/wiki/Extension:NativeSvgHandler/zh | NativeSvgHandler]扩展(将SVG文件直接发送至客户端以进行客户端渲染)。步骤如下:<br/>
1、页面提示:“<span style="color: red">'''生成缩略图出错:无法创建临时缩略图文件'''</span>”。
# '''下载文件,并将其放置在extensions/文件夹中的NativeSvgHandler目录内。(注意修改所有者及读写权限)'''
# '''将下列代码放置在您的LocalSettings.php的底部:'''<code>wfLoadExtension( 'NativeSvgHandler' );</code>''''''
2、在“'''[[特殊:文件列表]]'''”中查看文件时,提示:“<span style="color: red">'''Warning: symlink() has been disabled for security reasons in /www/wwwroot/wiki.eijux.com/includes/media/SvgHandler.php on line 280'''</span>”。
# '''导航至Special:Version,以验证扩展已成功安装。'''
 
再于网页刷新,svg缩略图显示正常。
'''解决:''' 在服务器的 PHP 配置中,将禁用的函数“<span style="color: blue; font-size: 120%">'''symlink()'''</span><ref>默认情况下,是被禁用的函数。可以使用“<span style="color: blue">宝塔面板</span>快速设置。”</ref>”删除。
 
 
=== “sh: convert: command not found” ===
生成缩略图处提示:<span style="color: red">'''sh: convert: command not found'''</span>。
 
<blockquote>
Mediawiki 支持 SVG 图像呈现:如果启用,SVG 图像可以像其他图像文件一样使用 —— 它们将自动呈现为 <span style="color: blue">'''PNG'''</span> 文件,并根据需要动态缩略图。
 
MediaWiki 默认没有安装任何“<span style="color: blue; font-size: 120%">'''转换器'''</span>”(Converter<ref>Converter("ImageMagick", "ImagickExt", "sodipodi", "inkscape", "batik", "rsvg", and "imgserv")均需单独安装。</ref>),以下选择安装“<span style="color: blue; font-size: 120%">'''NativeSvgHandler'''</span><ref>插件“'''NativeSvgHandler'''”:将 SVG 文件直接发送至客户端以进行客户端渲染。<br/>参考:[https://www.mediawiki.org/wiki/Extension:NativeSvgHandler/zh Extension:NativeSvgHandler]</ref>”。
</blockquote>
 
'''解决:'''
# 下载“'''NativeSvgHandler'''”到服务器(“./extensions/”)中;
#* 注意修改所有者及读写权限。
# 配置启动('''LocalSettings.php''' 中):
#: <syntaxhighlight lang="PHP" highlight="">
wfLoadExtension( 'NativeSvgHandler' );
</syntaxhighlight>
 
再于网页刷新,svg 缩略图显示正常。
 
 
=== “Warning: is_executable(): open_basedir ……” ===
PHP 错误信息为:<span style="color: red">'''Warning: is_executable(): open_basedir restriction in effect. File(/bin/bash) is not within the allowed path(s): (/www/wwwroot/wiki.eijux.com/:/tmp/) in /www/wwwroot/wiki.eijux.com/includes/shell/Command.php on line 311'''</span>。
 
'''解决:''' 参考:“'''[[#open_basedir 问题]]'''”。


* 如果要使用第三方的converter,参见[https://www.mediawiki.org/wiki/Manual:Installing_third-party_tools#Image_thumbnailing<nowiki> Image thumbnailing页面]</nowiki>
== 参考 ==
<references/>

2022年8月23日 (二) 22:26的最新版本


关于

手册:常见问题

open_basedir 问题

Warning: is_executable(): open_basedir restriction in effect. File(/bin/bash) is not within the allowed path(s): (/www/wwwroot/wiki.eijux.com/:/tmp/) in /www/wwwroot/wiki.eijux.com/includes/shell/Command.php on line 311

    MediaWiki:open basedir问题.png


open_basedir(防止跨站攻击) :用于将 PHP 所能打开的文件限制在指定的目录树,以此防止跨目录、跨站的访问。

1、本指令不受安全模式打开或者关闭的影响。

2、当一个脚本试图打开一个文件时,该文件的位置将被检查。

3、当文件在指定的目录树之外时 PHP 将拒绝打开它。

  • open_basedir 指定的限制是路径前缀,而非目录名。(如:设置“/dir/user”,则“/dir/user”和“/dir/user1”都是可以访问的)。
    • 所以如果要将访问限制在仅为指定的目录,应用斜线结束路径名(如:“/dir/user/”)。
  • open_basedir 若配置为 Linux 根目录“/”,则一定不会再报错,但是“防止跨站攻击”也就没啥意义了。


解决方案:

  1. 关闭“防止跨站攻击”
    1. 通过“宝塔面板”关闭:网站 -> 站点设置 -> 网站目录:取消“防止跨站攻击(open_basedir)”。如下图:
      宝塔面板:防止跨站攻击(open basedir).png
    2. 通过“配置文件”关闭:注销如下语句即禁用。
      ...
      
      phpIniOverride  {
      #php_admin_value open_basedir "/tmp/:/www/wwwroot/wiki.eijux.com/"
      }
      
      ...
      
      • 配置文件:位于“/www/server/panel/vhost/openlitespeed/detail/wiki.eijux.com.conf”。
  2. 配置“open_basedir”:修改“.user.ini”文件,添加必要的目录树。步骤:
    1. 根据错误信息,查找需要添加的目录;
      如上:“File(/bin/bash) 不在被允许的路径中”
      • 也可以根据“服务器上的站点错误日志[1]”。
    2. 确认“待添加目录”的“实际路径”:因为目录可能是 Symlink(符号链接);
      如上:“/bin/bash”就是指向“/usr/bin/bash”的符号链接。
    3. 开启站点的“防止跨站攻击”,并配置“.user.ini”文件:
      open_basedir=/www/wwwroot/wiki.eijux.com/:/tmp/:/usr/bin/bash
      
    4. 访问站点的文章页面,以确定不再有“open_basedir 问题”。
【2022/08/23 17:47:44 验证】


.user.ini”:用于配置“open_basedir”

1、开启“防止跨站攻击”后自动生成。(位于项目根目录)

2、关闭“防止跨站攻击”自动删除;

3、不能被上传覆盖,只能在服务器修改;


可以通过宝塔面板来修改宝塔面板:修改“.user.ini”.png

页面显示无格式

访问所有页面都只有文字,没有格式。如图:

    MediaWiki:“$wgScriptPath”设置导致页面显示格式不对.png

解决:

  1. 检查本地网络环境;
  2. 检查系统配置文件(“LocalSettings.php”)中的“$wgScriptPath[2]”配置。
    • $wgScriptPath”的配置与 MediaWiki 安装路径不匹配,会导致无法获取 MediaWiki 的各个脚本,从而出现上述情况。

SVG[3] 缩略图问题

初次上传 svg(矢量图)时,遇到了几个问题,基本上都是由于配置不完全导致。

“无法创建临时缩略图文件”

上传“.svg”文件后:

1、页面提示:“生成缩略图出错:无法创建临时缩略图文件”。

2、在“特殊:文件列表”中查看文件时,提示:“Warning: symlink() has been disabled for security reasons in /www/wwwroot/wiki.eijux.com/includes/media/SvgHandler.php on line 280”。

解决: 在服务器的 PHP 配置中,将禁用的函数“symlink()[4]”删除。


“sh: convert: command not found”

生成缩略图处提示:sh: convert: command not found

Mediawiki 支持 SVG 图像呈现:如果启用,SVG 图像可以像其他图像文件一样使用 —— 它们将自动呈现为 PNG 文件,并根据需要动态缩略图。

MediaWiki 默认没有安装任何“转换器”(Converter[5]),以下选择安装“NativeSvgHandler[6]”。

解决:

  1. 下载“NativeSvgHandler”到服务器(“./extensions/”)中;
    • 注意修改所有者及读写权限。
  2. 配置启动(LocalSettings.php 中):
    wfLoadExtension( 'NativeSvgHandler' );
    

再于网页刷新,svg 缩略图显示正常。


“Warning: is_executable(): open_basedir ……”

PHP 错误信息为:Warning: is_executable(): open_basedir restriction in effect. File(/bin/bash) is not within the allowed path(s): (/www/wwwroot/wiki.eijux.com/:/tmp/) in /www/wwwroot/wiki.eijux.com/includes/shell/Command.php on line 311

解决: 参考:“#open_basedir 问题”。

参考

  1. 位于:“/www/wwwlogs/wiki.eijux.com.error.log”。
  2. 手册:LocalSettings#$wgScriptPath
  3. 参考:Manual:Image administration#SVG
  4. 默认情况下,是被禁用的函数。可以使用“宝塔面板快速设置。”
  5. Converter("ImageMagick", "ImagickExt", "sodipodi", "inkscape", "batik", "rsvg", and "imgserv")均需单独安装。
  6. 插件“NativeSvgHandler”:将 SVG 文件直接发送至客户端以进行客户端渲染。
    参考:Extension:NativeSvgHandler