Home  >  Article  >  Backend Development  >  open_basedir怎么设置

open_basedir怎么设置

PHPz
PHPzOriginal
2016-06-06 20:52:434258browse

open_basedir怎么设置

open_basedir怎么设置?

open_basedir php授权目录设置

php为了安全性考虑,有一项 open_basedir 的设置。根据你web服务器环境,open_basedir可以在几个地方设置。

首先 在php.ini中配置。

;open_basedir =

如果发现配置项前是有分号,表明php.ini中没有该设置。那就很可能是在  php-fpm  中的 fastcgi.conf中配置了。php-fpm中的配置会覆盖php.ini的配置。

fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root:/tmp/:/proc/:/you_web_path";

/you_web_path 是你要添加的让php可以访问的路径。多个路径直接分号隔开

如果也给服务器有多个项目,无论是在php.ini或者fastcgi.cong中设置,都是针对所有项目。那能不能只针对某个项目设置呢?

答案是肯定的。还可以在项目根目录中通过  .user.ini 进行配置。

.user.ini配置

首先,要使.user.ini生效,要设置php.ini 中的

user_ini.filename = ".user.ini"
user_ini.cache_ttl = 300

关于这两个配置的意义,请看php手册 http://php.net/manual/zh/configuration.file.per-user.php

注释掉 fastcgi.conf 中的 open_basedir  的配置。

在项目根目录 创建 .user.ini文件,写入如下内容

open_basedir=/tmp/:/proc/:/you_web_path

/you_web_path 是你要添加的让php可以访问的路径。多个路径直接分号隔开

重启一下php-fpm 服务即可。

更多相关技术文章,请访问PHP中文网

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn