如下是php.ini中的原文說明以及默認配置:
;
open_basedir, if set, limits all file operations to the defined directory
; and below. This directive makes most sense if used in a per-directory or
; per-virtualhost web server configuration file. This directive is
; *NOT* affected by whether Safe Mode is turned On or Off.
open_basedir = .
open_basedir可將用戶訪問文件的活動范圍限制在指定的區(qū)域,通常是其家目錄的路徑,也
可用符號"."來代表當(dāng)前目錄。注意用
open_basedir指定的限制實際上是前綴,而不是目錄名。
舉例來說: 若"
open_basedir = /
dir/user", 那么目錄 "/
dir/user" 和 "/
dir/user1"都是
可以訪問的。所以如果要將訪問限制在僅為指定的目錄,請用斜線結(jié)束路徑名。例如設(shè)置成:
"
open_basedir = /
dir/user/"
open_basedir也可以同時設(shè)置多個目錄, 在Windows中用分號分隔目錄,在任何其它系統(tǒng)中用
冒號分隔目錄。當(dāng)其作用于Apache模塊時,父目錄中的
open_basedir路徑自動被繼承。
有三種方法可以在Apache中為指定的用戶做獨立的設(shè)置:
(a) 在Apache的httpd.conf中Directory的相應(yīng)設(shè)置方法:
php_admin_value open_basedir /usr/local/apache/htdocs/
#設(shè)置多個目錄可以參考如下:
php_admin_value open_basedir /usr/local/apache/htdocs/:/tmp/
(b) 在Apache的httpd.conf中VirtualHost的相應(yīng)設(shè)置方法:
php_admin_value open_basedir /usr/local/apache/htdocs/
#設(shè)置多個目錄可以參考如下:
php_admin_value open_basedir /var/www/html/:/var/tmp/
(c) 因為VirtualHost中設(shè)置了
open_basedir之后, 這個虛擬用戶就不會再自動繼承php.ini
中的
open_basedir設(shè)置值了,這就難以達到靈活的配置措施, 所以建議您不要在VirtualHost
中設(shè)置此項限制. 例如,可以在php.ini中設(shè)置
open_basedir = .:/tmp/, 這個設(shè)置表示允許
訪問當(dāng)前目錄(即PHP腳本文件所在之目錄)和/tmp/目錄.
請注意: 若在php.ini所設(shè)置的上傳文件臨時目錄為/tmp/, 那么設(shè)置
open_basedir時就必須
包含/tmp/,否則會導(dǎo)致上傳失敗. 新版php則會提示"
open_basedir restriction in effect"
警告信息, 但move_uploaded_file()函數(shù)仍然可以成功取出/tmp/目錄下的上傳文件,不知道
這是漏洞還是新功能.
針對ShopEx472版本的配置:
open_basedir = "D:/Server;../catalog;../include;../../home;../syssite;../templates;../language;../../language;../../../language;../../../../language"