简体   繁体   English

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

[英]PHP on Plesk - Can't see absolute directories

I have PHP installed on a web server administered by Plesk. 我在由Plesk管理的Web服务器上安装了PHP。 I am having some PHP include_path problems which I have narrowed down to absolute paths apparently not working. 我遇到了一些PHP include_path问题,这些问题已缩小为绝对路径,显然不起作用。

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? 有任何想法吗?

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. Plesk(或系统的其他部分)会将您的PHP实例限制在当前站点内,并且不允许浏览一般的var/www目录。

What user is your PHP running as? 您的PHP以哪个用户身份运行? Does that user have the right to access /var/www? 该用户是否有权访问/ var / www?

Plesk will add a variable like this in the httpd.conf include: Plesk将在httpd.conf中添加如下所示的变量:

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 . 因此您无法从锁httpdocs和/ tmp中列出任何父文件夹。 You can add manualy in your config file using a root ssh account. 您可以使用ssh根帐户在配置文件中手动添加。

Edit the httpd config file from your site in: /var/www/vhosts/_your_domain_/config/ . / var / www / vhosts / _your_domain_ / config /中从您的站点编辑httpd配置文件 _httpd.include (the Plesk 10 is a dynamic name that changes with a timestamp). _httpd.include (Plesk 10是随时间戳更改的动态名称)。

There you can search for php_admin_value open_basedir and add the folder that you want have access using : separator. 您可以在其中搜索php_admin_value open_basedir并使用:分隔符添加要访问的文件夹。 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. 但是,如果要为所有网站添加文件夹访问权限,例如/ usr / share / pear文件夹,则需要编辑plesk面板文件。

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

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. 并确保如果plesk得到更新将删除您的更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM