如下是php.ini中的原文說(shuō)明以及默認配置:
;
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可將用戶(hù)訪(fǎng)問(wèn)文件的活動(dòng)范圍限制在指定的區域,通常是其家目錄的路徑,也
可用符號"."來(lái)代表當前目錄。注意用
open_basedir指定的限制實(shí)際上是前綴,而不是目錄名。
舉例來(lái)說(shuō): 若"
open_basedir = /
dir/user", 那么目錄 "/
dir/user" 和 "/
dir/user1"都是
可以訪(fǎng)問(wèn)的。所以如果要將訪(fǎng)問(wèn)限制在僅為指定的目錄,請用斜線(xiàn)結束路徑名。例如設置成:
"
open_basedir = /
dir/user/"
open_basedir也可以同時(shí)設置多個(gè)目錄, 在Windows中用分號分隔目錄,在任何其它系統中用
冒號分隔目錄。當其作用于A(yíng)pache模塊時(shí),父目錄中的
open_basedir路徑自動(dòng)被繼承。
有三種方法可以在A(yíng)pache中為指定的用戶(hù)做獨立的設置:
(a) 在A(yíng)pache的httpd.conf中Directory的相應設置方法:
php_admin_value open_basedir /usr/local/apache/htdocs/
#設置多個(gè)目錄可以參考如下:
php_admin_value open_basedir /usr/local/apache/htdocs/:/tmp/
(b) 在A(yíng)pache的httpd.conf中VirtualHost的相應設置方法:
php_admin_value open_basedir /usr/local/apache/htdocs/
#設置多個(gè)目錄可以參考如下:
php_admin_value open_basedir /var/www/html/:/var/tmp/
(c) 因為VirtualHost中設置了
open_basedir之后, 這個(gè)虛擬用戶(hù)就不會(huì )再自動(dòng)繼承php.ini
中的
open_basedir設置值了,這就難以達到靈活的配置措施, 所以建議您不要在VirtualHost
中設置此項限制. 例如,可以在php.ini中設置
open_basedir = .:/tmp/, 這個(gè)設置表示允許
訪(fǎng)問(wèn)當前目錄(即PHP腳本文件所在之目錄)和/tmp/目錄.
請注意: 若在php.ini所設置的上傳文件臨時(shí)目錄為/tmp/, 那么設置
open_basedir時(shí)就必須
包含/tmp/,否則會(huì )導致上傳失敗. 新版php則會(huì )提示"
open_basedir restriction in effect"
警告信息, 但move_uploaded_file()函數仍然可以成功取出/tmp/目錄下的上傳文件,不知道
這是漏洞還是新功能.
針對ShopEx472版本的配置:
open_basedir = "D:/Server;../catalog;../include;../../home;../syssite;../templates;../language;../../language;../../../language;../../../../language"