skip to Main Content

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?

2

Answers


  1. 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?

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search