如何放宽 PHP 的 open_basedir 限制? [英] How can I relax PHP's open_basedir restriction?

查看:26
本文介绍了如何放宽 PHP 的 open_basedir 限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

open_basedir 限制了 PHP 在目录树中可以打开的文件.

我在 Web 根目录之外存储了几个类库和配置文件.通过这种方式,Web 服务器不会使它们可公开访问.但是,当我尝试从我的应用程序中包含它们时,我收到如下 open_basedir 限制错误:

<块引用>

警告:realpath()[function.realpath]: open_basedir限制生效.文件(/var/www/vhosts/domain.tld/zend/application)不在允许的路径内:(/var/www/vhosts/domain.tld/httpdocs:/tmp)在/var/www/vhosts/domain.tld/httpdocs/index.php第 5 行

我的网站根目录在这里:

/var/www/vhosts/domain.tld/httpdocs

我的库和配置目录在这里:

/var/www/vhosts/domain.tld/zend

放宽 open_basedir 限制以便域文件夹下的目录树可用于我的应用程序的最佳解决方法是什么?我有许多域想要这样做,而且我显然也很担心会产生安全漏洞.

注意:我使用的是 CentOS、Apache、Plesk,并且我拥有对服务器的 root ssh 访问权限.虽然这并不直接适用于 Zend Framework,但我在本例中使用了它.所以这里是 Zend 引导程序的内容:

define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../zend/application/'));set_include_path(APPLICATION_PATH.'/../zend/library'.PATH_SEPARATOR.get_include_path());

解决方案

您还可以使用 Apache(假设这是您的 Web 服务器)配置文件(例如 httpd.conf)在每个目录的基础上轻松完成此操作

>

<目录/var/www/vhosts/domain.tld/httpdocs>php_admin_value open_basedir "/var/www/vhosts/domain.tld/httpdocs:/var/www/vhosts/domain.tld/zend"</目录>

你也可以完全取消限制

<目录/var/www/vhosts/domain.tld/httpdocs>php_admin_value open_basedir 无</目录>

open_basedir limits the files that can be opened by PHP within a directory-tree.

I am storing several class libraries and configuration files outside of my web root directory. This way the web server does not make them publicly accessible. However when I try to include them from my application I get an open_basedir restriction error like this:

Warning: realpath() [function.realpath]: open_basedir restriction in effect. File(/var/www/vhosts/domain.tld/zend/application) is not within the allowed path(s): (/var/www/vhosts/domain.tld/httpdocs:/tmp) in /var/www/vhosts/domain.tld/httpdocs/index.php on line 5

My web root is here:

/var/www/vhosts/domain.tld/httpdocs

My libraries and configuration directory are here:

/var/www/vhosts/domain.tld/zend

What would be the best workaround to relax the open_basedir restriction so that the the directory tree under the domain folder becomes available to my application? I have a number of domains that I want to do this with, and I'm also obviously wary of creating security vulnerabilities.

Note: I am using CentOS, Apache, Plesk, and I have root ssh access to the server. And though this doesn't apply to Zend Framework directly, I am using it in this instance. So here is the inclusion from Zend's bootstrap:

define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../zend/application/'));
set_include_path(APPLICATION_PATH . '/../zend/library' . PATH_SEPARATOR . get_include_path());

解决方案

You can also do this easily on a per-directory basis using the Apache (assuming this is your web server) configuration file (e.g. httpd.conf)

<Directory /var/www/vhosts/domain.tld/httpdocs>
php_admin_value open_basedir "/var/www/vhosts/domain.tld/httpdocs:/var/www/vhosts/domain.tld/zend"
</Directory>

you can also completely remove the restriction with

<Directory /var/www/vhosts/domain.tld/httpdocs>
php_admin_value open_basedir none
</Directory>

这篇关于如何放宽 PHP 的 open_basedir 限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆