【发布时间】:2016-06-24 18:10:06
【问题描述】:
编辑:这 不是 open_basedir restriction in effect. File(/) is not within the allowed path(s): 的副本。这个问题与 PHP 设置无关,因为我有几个网站在相同的地图结构和相同的 PHP 设置下工作。请在将其标记为重复之前阅读整个问题,正如我在本问题的最后 4 段中解释的那样。此外,另一个问题的答案是针对 Apache 的,而我使用的是 Nginx,它不使用 CPanel 或 httpd.conf。
我已手动将我的 Wordpress 网站移至新服务器。对于最后一个,我收到此错误:
Warning: is_dir(): open_basedir restriction in effect. File(/) is not
within the allowed path(s):
(/var/hpwsites/u_bcsautoborg:/usr/share/pear/) in
/var/hpwsites/u_bcsautoborg/website/html/webroot/wp-includes/functions.php on
line 1585
我之前在网站上遇到过类似的错误,但那是由于没有从 Wordpress 设置正确链接到 upload 文件夹。因此,错误显示了不同的行号。
第 1585 行是:
while ( '.' != $target_parent && ! is_dir( $target_parent ) ) {
并且是较大块的一部分:
/*
* Safe mode fails with a trailing slash under certain PHP versions.
* Use rtrim() instead of untrailingslashit to avoid formatting.php dependency.
*/
$target = rtrim($target, '/');
if ( empty($target) )
$target = '/';
if ( file_exists( $target ) )
return @is_dir( $target );
// We need to find the permissions of the parent folder that exists
and inherit that.
$target_parent = dirname( $target );
while ( '.' != $target_parent && ! is_dir( $target_parent ) ) {
$target_parent = dirname( $target_parent );
}
这是来自 Wordpress 函数文件。从代码来看,我认为问题出在$target_parent,但我不知道它指的是什么,因为我对 PHP 不是很好。
现在我知道open_basedir restriction 错误通常意味着 PHP.ini 文件的安全设置不正确,不允许 PHP 函数访问所需的文件夹。但是,我确定这里不是这种情况。
这是一个工作网站,与我所有其他网站的结构相同。所有都托管在 Apache 服务器上,我正在迁移到 Nginx 服务器,并且都有自己的目录,有自己的 MySQL 数据库,所有目录都包含相同的文件和文件夹(除了网站特定的文件夹当然)。所有其他网站都在与此相同的设置中完美运行,因此我无法想象这是一个 php.ini 问题。
在前一种情况下,问题在于“上传”文件夹,我仍然能够进入 wp-admin 并通过 Wordpress 设置更改上传文件夹的位置。但是,我现在无法进入任何页面,因为我只收到上述错误,它重复到无穷大。
我已通过 PHPmyAdmin 禁用所有插件,但无济于事。显然,我已经在 SO、wordpress 论坛、Google 和 DuckDuckGo 上寻找解决方案。我发现了许多类似的问题,但我找到的解决方案都不适合我。
有人知道原因可能在哪里吗?
【问题讨论】:
-
我不知道 $target 来自哪里,但它似乎是空的或等于 '/' 而不是表示允许文件路径的字符串。没有完整的源代码不能说太多,但我知道你不能在这里发布 Wordpress 源代码:)
-
$target来自哪里?抛出错误是有道理的,因为您肯定不希望应用访问您的根目录。 -
在这里找到源:github.com/WordPress/WordPress/blob/master/wp-includes/… 但需要回溯才能知道发生了什么......
-
@Derek 感谢您到目前为止的回复。我不确定你所说的“回溯”是什么意思。这是我可以检索到的东西吗?如果可以,如何检索?
-
@Derek @Jonathan 我查看了 Derek 链接的源代码,但我注意到源代码与我的
functions.php文件不同。值得注意的是;在我的网站上产生错误的行是 1585,但在链接源中,第 1609 行可以找到第 1585 行的内容,而链接源中的第 1585 行具有完全不同的内容。我的functions.php中似乎缺少某些内容,这可能是由于在服务器之间复制/粘贴文件时出错引起的吗?
标签: php wordpress nginx open-basedir