php open_basedir

来自http://tunps.com/php-open_basedir

在php写了句require_once ‘../Zend/Loader.php’; 报错:
Warning: require_once() [function.require-once]: open_basedir restriction in effect. File(../Zend/Loader.php) is not within the allowed path(s): (D:\phpnow\vhosts\zf.com;C:\Windows\Temp;) in D:\phpnow\vhosts\zf.com\index.php on line 6

Warning: require_once(../Zend/Loader.php) [function.require-once]: failed to open stream: Operation not permitted in D:\phpnow\vhosts\zf.com\index.php on line 6

Fatal error: require_once() [function.require]: Failed opening required '../Zend/Loader.php' (include_path='D:\phpnow\vhosts\zf.comZend;.;C:\php5\pear') in D:\phpnow\vhosts\zf.com\index.php on line 6
字面分析是受到了open_basedir的限制,造成Operation not permitted(操作不被允许)。 打开php.ini跳转到open_basedir相关设置段落:
; 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,那么所有能被操作的文件就只能限制在open_basedir指定的目录里面。 这个在虚拟主机里面这个指令相当有用。不管安全模式是否打开,这个指令都不受影响。 看来php.ini没有设置open_basedir。 打开apache虚拟主机配置文件:
<virtualhost *>
    <directory "../vhosts/zf.com">
        Options -Indexes FollowSymLinks
    </directory>
    ServerAdmin admin@zf.com
    DocumentRoot "../vhosts/zf.com"
    ServerName zf.com:80
    ServerAlias *.zf.com
    ErrorLog logs/zf.com-error_log
    php_admin_value open_basedir "D:\phpnow\vhosts\zf.com;C:\Windows\Temp;"
</virtualhost>
里面的php_admin_value open_basedir就限定了操作目录。 我这里是本地测试,安全因素不考虑,直接将 php_admin_value open_basedir “D:\phpnow\vhosts\zf.com;C:\Windows\Temp;” 删除掉,重新启动apache,ok。

About tunpishuang

just 4 fun·····
This entry was posted in 未分类 and tagged . Bookmark the permalink.

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>