yiiext / zend-autoloader-component

Fast autoloader for Zend Framework classes.
http://www.yiiframework.com/extension/zendautoloader
5 stars 1 forks source link

open_basedir error #7

Closed GerhardLiebenberg closed 8 years ago

GerhardLiebenberg commented 8 years ago

We are hosting with Hetzner. Yii 1.

The following code in YiiBase >> autoload() produces an error:

foreach(self::$_includePaths as $path)
{
    $classFile=$path.DIRECTORY_SEPARATOR.$className.'.php';
    if(is_file($classFile))  // **** this line produces the error ****
    {
        include($classFile);
        if(YII_DEBUG && basename(realpath($classFile))!==$className.'.php')
            throw new CException(Yii::t('yii','Class name "{class}" does not match class file "{file}".', array(
            '{class}'=>$className,
            '{file}'=>$classFile,
        )));
        break;
    }
}

The error is: is_file(): open_basedir restriction in effect. File(/usr/share/pear/Zend_Mail_Transport_Smtp.php) is not within the allowed path(s):

What I think might be happening:

  1. Zend_Mail_Transport_Smtp is a class, but Yii is first trying to locate it as a file.
  2. When it can't find the file in any of the allowed paths, it throws the error before using EZendAutoloader() to try and load it as a class.

Zend_Mail_Transport_Smtp is a class in Zend/Mail/Transport/Smtp.php

Everything works fine on my local computer with php 5.4, but the server runs php 5.6. Maybe it is a php issue?

samdark commented 8 years ago

Try \Zend_Mail_Transport_Smtp. Overall it's not Yii issue.

GerhardLiebenberg commented 8 years ago

Hi Samdark,

Yes, the error occurs while trying to load Zend_Mail_Transport_Smtp.

I don't think it will help to import all the zend folders, because Zend_Mail_Transport_Smtp is not a file and Yii will therefore still not find it. Any other ideas?

samdark commented 8 years ago

Ah, thought it's Yii 2.0 issue :)

samdark commented 8 years ago

No ideas.

GerhardLiebenberg commented 8 years ago

Could be a php bug: http://stackoverflow.com/questions/22366160/warning-open-basedir-restriction-in-effect-caused-by-trailing-path-after-php-fi

It is working fine if I replace is_file() with @is_file(). I hate to change the core files though.

cebe commented 8 years ago

can you show your php config include_path?

GerhardLiebenberg commented 8 years ago

On the server: .:/usr/share/php56:/usr/share/pear

On my pc: include_path = ".;C:\xampp\php\PEAR"

GerhardLiebenberg commented 8 years ago

In index.php I have: Yii::import('common.extensions.EZendAutoloader', true); EZendAutoloader::$prefixes = array('Zend'); EZendAutoloader::$basePath = Yii::getPathOfAlias('common.lib') . DIRECTORY_SEPARATOR; Yii::registerAutoloader(array("EZendAutoloader", "loadClass"), true);

In config file I have: 'import' => array( 'common.lib.*',

This bug report describes the same behaviour: https://bugs.php.net/bug.php?id=41518

cebe commented 8 years ago

this is definitifely a server configuration issue, if you do no allow accessing those paths, they should not be in include_path. Either adjust open basedir setting or the include path.

GerhardLiebenberg commented 8 years ago

Hi Cebe. I found out last night:

If I have this in index.php: $r = is_file('/usr/share/pear/Zend_Mail_Transport_Smtp.php'); $app = Yii::createApplication('WebApplication', $config); then no error is thrown and $r = false.

But if I switch them around: $app = Yii::createApplication('WebApplication', $config); $r = is_file('/usr/share/pear/Zend_Mail_Transport_Smtp.php'); then the error is displayed.

I'm busy deleting sections of the application to try and isolate the cause.

cebe commented 8 years ago

that is because the error is a warning, which will be caught by the Yii errorhandler which only takes effect after the application has been created, the problem is still the same, you must not try to access files that are outside the open_basedir restriction.

GerhardLiebenberg commented 8 years ago

The warning is displayed when the file is being searched for in /usr/share/pear. But /usr/share/pear is included as one of the valid directories on the server - so the warning does not make sense.

What I noticed is that /usr/share/pear was the last of all the available directories to be inspected. So I'm wondering: a) is there something specifically wrong with /usr/share/pear OR b) is the warning displayed simply because the file was not found in any of the valid paths?

If it is (b), then we have a problem. The server now runs php 5.6.

cebe commented 8 years ago

what is your open_basedir setting? http://php.net/manual/de/ini.core.php#ini.open-basedir

GerhardLiebenberg commented 8 years ago

include_path: .:/usr/share/php56:/usr/share/pear

open_basedir: /usr/www/wwws/users/intersfzdk: /usr/wwws/users/intersfzdk: /usr/www/users/intersfzdk: /usr/home/intersfzdk: /usr/local/rmagic: /usr/www/users/he/system: /usr/share/php56: /usr/local/lib/php56: /tmp: /usr/bin: /usr/local/bin: /usr/local/share/www: /usr/www/share/www: /usr/share/misc

Hmm... /usr/share/php56 is in both include_path and open_basedir. But usr/share/pear is only in the include_path.

cebe commented 8 years ago

But usr/share/pear is only in the include_path.

and that is your problem.

GerhardLiebenberg commented 8 years ago

Many thanx Cebe. I showed that to the hosting company and they agreed it is their mistake. They are trying to find the problem.

Thank you for your time.