php 如何为特定目录设置open_basedir
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13291185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set for specific directory open_basedir
提问by L84
I have a directory /htdocs/unsecuredand I want to limit whatever is in that directory or its subdirectories from accessing anything outside of that directory. Where and how do I set open_basedirfor this directory only?
我有一个目录/htdocs/unsecured,我想限制该目录或其子目录中的任何内容访问该目录之外的任何内容。我在哪里以及如何open_basedir只为这个目录设置?
回答by newfurniturey
You can set open_basedirin your Apache configuration file, php.ini, or in a .htaccess file.
您可以open_basedir在 Apache 配置文件 php.ini 或 .htaccess 文件中进行设置。
I normally set this in an apache config file such as /etc/httpd/conf/httpd.conf.
我通常在 apache 配置文件中设置它,例如 /etc/httpd/conf/httpd.conf。
You will have a directory structure for your current domain/virtual-host and you can add the line directly in there:
您将拥有当前域/虚拟主机的目录结构,您可以直接在其中添加该行:
<VirtualHost 123.123.123.123:80>
<Directory /htdocs/unsecured>
php_admin_value open_basedir "C:/htdocs/unsecured"
</Directory>
</VirtualHost>
Note:The 123.123.123.123is the IP address of your domain andthis sample block potentially leaves out a lotof data for this configuration only showing what's needed for open_basedir.
注:该123.123.123.123是你的域名的IP地址和该样品板可能遗漏了大量数据的此配置只显示什么需要的open_basedir。
In php.ini, you can do this on a much-more general level (and it will be applied to everydomain on your server) with:
在 php.ini 中,您可以在更一般的级别上执行此操作(它将应用于您服务器上的每个域):
open_basedir = "/htdocs/unsecured"
In .htaccess, you should be able to use the following (though I haven't tested):
在 .htaccess 中,您应该能够使用以下内容(虽然我还没有测试过):
php_value open_basedir "/htdocs/unsecured"
EDIT(Windows path)
Per a comment, you're running xammp on Windows (and not using Virtual Hosts). With this information, I would suggest to put your open_basedirrule in your php.inifile. This should (hopefully) work for you:
编辑(Windows 路径)
根据评论,您在 Windows 上运行 xammp(而不是使用虚拟主机)。有了这些信息,我建议将您的open_basedir规则放在您的php.ini文件中。这应该(希望)对你有用:
open_basedir = "C:\xampp\htdocs\unsecured"
In linux, a :is a field separator. In Windows, the ;is the separator - so this shouldwork, but I am unable to test it personally.
在 linux 中,a:是字段分隔符。在 Windows 中,;是分隔符 - 所以这应该可以工作,但我无法亲自测试它。
回答by Ene
You may change the open_basedirin php.ini, in your httpd.conf or during runtime as well.
您可以在 php.ini、httpd.conf 或运行时更改 open_basedir。

