给梦一个奔跑的方向!
PDF Print E-mail
User Rating: / 0
PoorBest 
Written by xlingfairy
Friday, 19 September 2008 23:23

第一处修定,我以前发到:http://home.blueidea.com/space.php?uid=164225&do=blog&id=7374 上了。这里引用一下。

joomla 的 libraries/joomla/filesystem/folder.php 的 create 方法,在某些环境下会出错,导至安装扩展不成功。
其原因就是 open_basedir 的问题。

这个 open_basedir 在 php.ini 里可以设定,也可以在 apache的httpd.conf 及 /apache/conf/extra/httpd-vhosts.conf 中设定,如:

<VirtualHost *:80>
ServerAdmin xling@joomla.com
DocumentRoot "/usr/web/joomla/www"
php_admin_value upload_tmp_dir "/usr/web/joomla/tmp"
php_admin_value open_basedir "/usr/web/joomla/www:/usr/web/joomla/tmp"

ServerName joomla
ErrorLog "/usr/web/joomla/error_log"
CustomLog "/usr/web/joomla/access_log" common
</VirtualHost>


看 folder.php,找到 create 方法,

// If open_basedir is set we need to get the open_basedir that the path is in
if ($obd != null)
{
if (JPATH_ISWIN) {
$obdSeparator = ";";
} else {
$obdSeparator = ":";
}
// Create the array of open_basedir paths
$obdArray = explode($obdSeparator, $obd);
$inOBD = false;
// Iterate through open_basedir paths looking for a match
foreach ($obdArray as $test) {
$test = JPath::clean($test);

if (strpos($path, $test) === 0) {
$obdpath = $test;
$inOBD = true;
break;
}
}
if ($inOBD == false) {
// Return false for JFolder::create because the path to be created is not in open_basedir
JError::raiseWarning('SOME_ERROR_CODE', 'JFolder::create: '.JText::_('Path not in open_basedir paths'));
return false;
}

函数中以经做了注解:If open_basedir is set we need to get the open_basedir that the path is in。
表面看是没有 open_basedir 的错了,但是实际上,还是会有,我给出我遇到的环境(linux):

1,新建一个 symble link 指向网站根目录。
ln -s /DISK_D/WEB/joomla /usr/web/joomla
/usr/web 这个目录必须存在。上面这步操作后,你 cd /usr/web/joomla 实际上就是进入了 /DISK_D/WEB/joomla 了

2,然后按上面给出的 httpd-vhosts.conf 片段进行设置
3,重启 apache 服务,

4,这时, $_SERVER['DOCUMENT_ROOT'] 就不是 /DISK_D/WEB/joomla/www了,而是 /usr/web/joomla/ww 了。
5,realpath('/') or die ('Not Allowed!') 试一下,结果是:Not Allowed,产生一个 warning,这就是 open_basedir 的功劳了。
6,在分析 folder.php ,
$test = JPath::clean($test);
$test 的结果是 /usr/web/joomla/www/xxx 而 参数 $path 却是真实的地址: /DISK_D/WEB/joomla/www/xxx
那里它只做一个简单的 strpos 来判断,当然是不正确的了!

7,realpath($_SERVER['DOCUMENT_ROOT']) 得到的结果是 : /DISK_D/WEB/joomla/www ,我就用这个来对该方法做一下修正:
在 $test = JPATH::clean($test);下加:
$test = @realpath($test);

第二处修定:

我也说不准是不是改的是否完美。还是上面那一段:

if (strpos($path, $test) === 0) {

我在这一句前用 var_dump(strpos($path,$test)) 得到的结果居然是 bool 值 false ( 0 == false , 0 !== false).也不知道是为啥。

就因为原文用了亚格等于(===),所以条件不成立,还是出错。我把严格等于换成等于,就行了。

Last Updated ( Wednesday, 11 March 2009 15:09 )
 

Add comment


Security code
Refresh

Popular Contents

Recommend

Related Articles

Site Info

Members : 1
Content : 100
Web Links : 7
Content View Hits : 56177

Links