php open_basedir设置

设置 php open_basedir 文件 需要 方法 open_basedir= tmp proc home 编程进阶笔记
发布日期 2022-10-07 更新日期 2022-10-07 阅读次数 82 文章字数 717

以下三种设置方法均需要PHP版本为5.3或者以上。

方法1)在Nginx配置文件中加入

fastcgi_param  PHP_VALUE  "open_basedir=$document_root:/tmp/:/proc/"; 

通常nginx的站点配置文件里用了include fastcgi.conf;,这样的,把这行加在fastcgi.conf里就OK了。
如果某个站点需要单独设置额外的目录,把上面的代码写在include fastcgi.conf;这行下面就OK了,会把fastcgi.conf中的设置覆盖掉。
这种方式的设置需要重启nginx后生效。

方法2)在php.ini中加入:

[HOST=www.server110.com]
open_basedir=/home/www/www.server110.com:/tmp/:/proc/
[PATH=/home/www/www.server110.com]
open_basedir=/home/www/www.server110.com:/tmp/:/proc/

这种方式的设置需要重启php-fpm后生效。

方法3)在网站根目录下创建.user.ini并写入:

open_basedir=/home/www/www.server110.com:/tmp/:/proc/

这种方式不需要重启nginx或php-fpm服务。安全起见应当取消掉.user.ini文件的写权限。
关于.user.ini文件的详细说明:
http://php.net/manual/zh/configuration.file.per-user.php

设置open_basedir的同时最好禁止下执行命令的函数,比如:
exec('ls /etc')仍然查看到/etc目录的文件列表
exec('cat /etc/passwd')仍可查看到/etc/passwd文件的内容


文章作者: 朱丰华

文章链接: https://smart.52dixiaowo.com/blog/post-112.html

版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。

设置 php open_basedir 文件 需要 方法 open_basedir= tmp proc home

发表评论

相关推荐
朱丰华   |   2个月前   |   对象 · 属性 · 反射 · js

js 对象反射 Reflect

104    评论    点赞
朱丰华   |   3个月前   |   启动 · php

debian12开机启动sh

197    评论    点赞
朱丰华   |   4个月前   |   sql · mysql · 字节 · 字符

mysql常用字段类型详解

130    评论    点赞
朱丰华   |   1年前   |   git

git从缓存中移除数据git rm --cached

509    评论    点赞
朱丰华   |   1年前   |   php

php判断是否被iframe

328    评论    点赞
朱丰华   |   1年前   |   页面 · 监听

iframe子父页面信息传递与监听

540    评论    点赞
朱丰华   |   1年前   |   linux · upx

Linux下安装UPX

620    评论    点赞
朱丰华   |   1年前   |   linux

linux保持后台进程不被关闭nohup &

327    评论    点赞
朱丰华   |   1年前   |   php

php正则表达式定界符:异常Delimiter must not be alphanumeric or backslash

252    评论    点赞
朱丰华   |   1年前   |   sql · mysql

mysql Timestamp或dateTime格式筛选

185    评论    点赞
朱丰华   |   1年前   |   请求 · 一个

ab测压命令,apache测压工具

244    评论    点赞
朱丰华   |   1年前   |   php · 缓存 · opcache

php 加速、提高并发opcache

299    评论    点赞
朱丰华   |   1年前   |   < · iframe

让iframe嵌入的视频自适应 (100%宽度)?

209    评论    点赞
朱丰华   |   1年前   |   go · gopath

Go自定义包并安装(GOPATH)

167    评论    点赞
朱丰华   |   1年前   |   正则 · 表达

正则表达式,实现if...then...else

181    评论    点赞
朱丰华   |   1年前   |   变量 · mysql · sql · 用户

MySQL用户自定义变量

150    评论    点赞
朱丰华   |   1年前   |   sql · php

PHP如何使用PDO批量执行SQL?

172    评论    点赞
朱丰华   |   1年前   |   sed · 文件

Shell 指定行处理head、tail、sed

202    评论    点赞
朱丰华   |   1年前   |   linux · 内容

linux环境下,对于一个大文件,如何查看其中某行的内容

115    评论    点赞
朱丰华   |   1年前   |   php · 字符 · 字符串

如何在 PHP 中将字符串的第一个字母转换为大写

208    评论    点赞
{{item.author_name}}   |   {{new Date(item.date*1000).log()}}   |   {{it}} ·

{{item.title}}

{{item.uv}}    评论    点赞