php 运行时 is not writable、open_basedir restriction in effect

在命令行运行php时,如果命令中有文件操作,经常会出现如下错误。

PHP Warning:  realpath(): open_basedir restriction in effect. File(/a/apps/linuxdef/composer) is not within the allowed path(s): (/tmp/) in - on line 626
PHP Warning:  is_writeable(): open_basedir restriction in effect. File(/a/apps/linuxdef/composer) is not within the allowed path(s): (/tmp/) in - on line 628
The installation directory "/a/apps/linuxdef/composer" is not writable

这是因为php.ini中open_basedir可将用户访问文件的活动范围限制在指定的区域。
可用符号”.”来代表当前目录。注意用open_basedir指定的限制实际上是前缀,而不是目录名 。
举例来说: 若”open_basedir = /dir/user”, 那么目录 “/dir/user” 和 “/dir/user1”都是
可以访问的。所以如果要将访问限制在仅为指定的目录,请用斜线结束路径名。例如设置成:
“open_basedir = /dir/user/”

open_basedir也可以同时设置多个目录, 在Windows中用分号分隔目录,在任何其它系统中用
冒号分隔目录 。当其作用于Apache模块时,父目录中的open_basedir路径自动被继承。

有三种方法可以在Apache中为指定的用户做独立的设置:

(a) 在Apache的httpd.conf中Directory的相应设置方法:

 php_admin_value open_basedir /usr/local/apache/htdocs/

设置多个目录可以参考如下:

 php_admin_value open_basedir /usr/local/apache/htdocs/:/tmp/

(b) 在Apache的httpd.conf中VirtualHost的相应设置方法:
php_admin_value open_basedir /usr/local/apache/htdocs/

设置多个目录可以参考如下:

php_admin_value open_basedir /var/www/html/:/var/tmp/

最能解决一切问题的是 加一个/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值