Plesk 上的 PHP - 无法查看绝对目录

发布于 2024-08-17 20:08:25 字数 748 浏览 2 评论 0原文

我在 Plesk 管理的 Web 服务器上安装了 PHP。我遇到了一些 PHP include_path 问题,我已将其范围缩小到绝对路径,但显然不起作用。

因此,如果我尝试执行目录列表,则以下工作有效:

echo "<h3>Directory listing of .</h3>";
foreach (new DirectoryIterator('.') as $fileInfo) {
    if($fileInfo->isDot()) continue;
    echo $fileInfo->getFilename() . "<br>\n";
};

但这没有输出。 (那里有文件)。

echo "<h3>Directory listing of /var/www</h3>";
foreach (new DirectoryIterator('/var/www') as $fileInfo) {
    if($fileInfo->isDot()) continue;
    echo $fileInfo->getFilename() . "<br>\n";
};

输出:

Directory listing of .
.htaccess
index.php
try.php

Directory listing of /var/www

有什么想法吗?

I have PHP installed on a web server administered by Plesk. I am having some PHP include_path problems which I have narrowed down to absolute paths apparently not working.

So, if I try to do a directory listing, the following works:

echo "<h3>Directory listing of .</h3>";
foreach (new DirectoryIterator('.') as $fileInfo) {
    if($fileInfo->isDot()) continue;
    echo $fileInfo->getFilename() . "<br>\n";
};

But this gives no output. (There are files there).

echo "<h3>Directory listing of /var/www</h3>";
foreach (new DirectoryIterator('/var/www') as $fileInfo) {
    if($fileInfo->isDot()) continue;
    echo $fileInfo->getFilename() . "<br>\n";
};

Output:

Directory listing of .
.htaccess
index.php
try.php

Directory listing of /var/www

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

少女七分熟 2024-08-24 20:08:25

如果这是多站点服务器设置,这可能是正常行为。 Plesk(或系统的其他部分)会将您的 PHP 实例限制在当前站点,并且不允许查看常规 var/www 目录。

你的 PHP 是以什么用户身份运行的?
该用户是否有权访问/var/www?

If this is a multi-site server setup, this may be normal behaviour. Plesk (or some other part of your system) would confine your PHP instance to your current site, and not allow a peek into the general var/www directory.

What user is your PHP running as?
Does that user have the right to access /var/www?

吻安 2024-08-24 20:08:25

Plesk 将在 httpd.conf include 中添加如下变量:

php_admin_value open_basedir /var/www/vhosts/_web_domain_/httpdocs/:/tmp/

这样您就无法列出锁定 httpdocs 和 /tmp 中的任何父文件夹。您可以使用 root ssh 帐户在配置文件中手动添加。

从您的站点编辑 httpd 配置文件:/var/www/vhosts/_your_domain_/config/._httpd.include(Plesk 10 是动态名称,随时间戳)。

您可以在其中搜索 php_admin_value open_basedir 并使用 : 分隔符添加您希望有权访问的文件夹。例如:

php_admin_value open_basedir /var/www/vhosts/_web_domain_/httpdocs/:/tmp/:/var/www

但是如果您想为所有网站添加文件夹访问权限,例如 /usr/share/pear 文件夹,您将需要编辑 plesk 面板文件。

编辑 /usr/local/psa/admin/conf/templates/default/service/php.php,从: 更改

echo "php_admin_value open_basedir {$OPT['dir']}/:/tmp/\n";

为:

echo "php_admin_value open_basedir {$OPT['dir']}/:/usr/share/pear/:/tmp/\n";

请记住,这将授予对该文件夹的所有网站的访问权限,可能会破坏服务器安全。请自行承担风险。请记住,如果 plesk 更新将会删除您的更改。

Plesk will add a variable like this in the httpd.conf include:

php_admin_value open_basedir /var/www/vhosts/_web_domain_/httpdocs/:/tmp/

so you can't list any parent folder from your lock httpdocs and /tmp. You can add manualy in your config file using a root ssh account.

Edit the httpd config file from your site in: /var/www/vhosts/_your_domain_/config/._httpd.include (the Plesk 10 is a dynamic name that changes with a timestamp).

There you can search for php_admin_value open_basedir and add the folder that you want have access using : separator. Like:

php_admin_value open_basedir /var/www/vhosts/_web_domain_/httpdocs/:/tmp/:/var/www

But if you want to add a folder access for all your websites, like /usr/share/pear folder, you will need to edit the plesk panel files.

Edit /usr/local/psa/admin/conf/templates/default/service/php.php, change from:

echo "php_admin_value open_basedir {$OPT['dir']}/:/tmp/\n";

To:

echo "php_admin_value open_basedir {$OPT['dir']}/:/usr/share/pear/:/tmp/\n";

Remamber that will give access to all websites to the folder, can break the server security. Do at your own risk. And remamber that if plesk get updated will erase your changes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文