php open_basedir 限制生效。文件(/)不在允许的路径内:
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1846882/
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
open_basedir restriction in effect. File(/) is not within the allowed path(s):
提问by Webnet
I'm getting this error on an avatar upload on my site. I've never gotten it before and nothing was changed recently for me to begin getting this error...
我在我网站上的头像上传中收到此错误。我以前从未得到过它,最近没有任何变化让我开始收到此错误...
Warning: is_writable() [function.is-writable]:
open_basedir restriction in effect.
File(/) is not within the allowed path(s):
采纳答案by Nikesh
Modify the open_basedirsettingsin your PHP configuration (See Runtime Configuration).
修改PHP 配置中的open_basedir设置(请参阅运行时配置)。
The open_basedirsetting is primarily used to prevent PHP scripts for a particular user from accessing files in another user's account. So usually, any files in your own account should be readable by your own scripts.
该open_basedir设置主要用于防止特定用户的 PHP 脚本访问其他用户帐户中的文件。所以通常,您自己帐户中的任何文件都应该可以被您自己的脚本读取。
Example settings via .htaccessif PHP runs as Apache module on a Linux system:
.htaccess如果 PHP 在 Linux 系统上作为 Apache 模块运行,则示例设置:
<DirectoryMatch "/home/sites/site81/">
php_admin_value open_basedir "/home/sites/site81/:/tmp/:/"
</DirectoryMatch>
回答by yogihosting
Modify the open_basedir settings in your hosting account and set them to none. Find the open_basedir setting given under 'PHP Settings' area of your Plesk/cPanel. Set it to 'none' from the dropdown given there. I have shown them in the Plesk panel picture.
修改您的主机帐户中的 open_basedir 设置并将它们设置为 none。在 Plesk/cPanel 的“PHP 设置”区域下找到 open_basedir 设置。从那里给出的下拉列表中将其设置为“无”。我已经在 Plesk 面板图片中展示了它们。
回答by Andrei
To resolve this error, you must edit the file httpd.conf. Way before it can be seen in phpinfo in apache2handler section directive Server Root. For example, in my case this way - / etc / httpd / httpd.conf. Open the file httpd.conf, find the mention of the parameter open_basedir. And set it to none. (php_admin_value open_basedir none)
要解决此错误,您必须编辑文件 httpd.conf。之前的方式可以在 phpinfo 中的 apache2handler 部分指令 Server Root 中看到。例如,在我的情况下这种方式 - /etc/httpd/httpd.conf。打开文件httpd.conf,找到参数open_basedir 的提及。并将其设置为无。( php_admin_value open_basedir none)
回答by Josh P
For me the problem was bad/missing config values for the Plesk server running the whole thing. I just followed the directions here: http://davidseah.com/blog/2007/04/separate-php-error-logs-for-multiple-domains-with-plesk/
对我来说,问题是运行整个事情的 Plesk 服务器的配置值错误/丢失。我只是按照这里的说明进行操作:http: //davidseah.com/blog/2007/04/separate-php-error-logs-for-multiple-domains-with-plesk/
You can configure PHP to have a separate error log file for each VirtualHost definition. The trick is knowing exactly how to set it up, because you can't touch the configuration directly without breaking Plesk. Every domain name on your (dv) has its own directory in /var/www/vhosts. A typical directory has the following top level directories:
您可以将 PHP 配置为每个 VirtualHost 定义都有一个单独的错误日志文件。诀窍在于确切地知道如何设置它,因为您无法在不破坏 Plesk 的情况下直接接触配置。您 (dv) 上的每个域名在 /var/www/vhosts 中都有自己的目录。典型的目录具有以下顶级目录:
cgi-bin/
conf/
error_docs/
httpdocs/
httpsdocs/
...and so on
You'll want to create a vhost.conf file in the domain directory's conf/ folder with the following lines:
您需要在域目录的 conf/ 文件夹中使用以下行创建一个 vhost.conf 文件:
php_value error_log /path/to/error_log
php_flag display_errors off
php_value error_reporting 6143
php_flag log_errors on
Change the first value to match your actual installation (I used /tmp/phperrors.log). After you're done editing the vhost.conf file, test the configuration from the console with:
更改第一个值以匹配您的实际安装(我使用 /tmp/phperrors.log)。完成 vhost.conf 文件的编辑后,使用以下命令从控制台测试配置:
apachectl configtest
…or if you don't have apachectl (as Plesk 8.6 doesn't seem to)…
/etc/init.d/httpd configtest
And finally tell Plesk that you've made this change.
最后告诉 Plesk 您已经进行了此更改。
/usr/local/psa/admin/bin/websrvmng -a
回答by deathangel908
If you're running this with php file.php. You need to edit php.iniFind this file:
如果您使用php file.php. 您需要编辑php.ini查找此文件:
: locate php.ini
/etc/php/php.ini
And append file's path to open_basedirproperty:
并将文件的路径附加到open_basedir属性:
open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/:/run/media/andrew/ext4/protected
open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/:/run/media/andrew/ext4/protected
回答by Bartuzz
I had this problem @ one of my wordpress sites after updating and/or moving :)
更新和/或移动后,我在我的一个 wordpress 网站上遇到了这个问题:)
Check in database table 'wp_options' the 'upload_path' and edit it properly...
检查数据库表'wp_options''upload_path'并正确编辑它......
回答by Qlimax
if you have this kind of problem with ispconfig3 and got an error like this
如果您在使用 ispconfig3 时遇到此类问题并收到这样的错误
open_basedir restriction in effect. File(/var/www/clients/client7/web15) is not within the allowed path(s):.........
open_basedir 限制生效。文件(/var/www/clients/client7/web15)不在允许的路径内:........
To solve it (in my case) , just set PHP to SuPHP in the Website's panel of ispconfig3
要解决它(在我的情况下),只需在 ispconfig3 的网站面板中将 PHP 设置为 SuPHP
Hope it helps someone :)
希望它可以帮助某人:)
回答by NDM
The path you're refering to is incorect, and not withing the directoryRoot of your workspace. Try building an absolute path the the file you want to access, where you are now probably using a relative path...
您引用的路径不正确,并且不包含工作区的 directoryRoot。尝试构建您要访问的文件的绝对路径,您现在可能正在使用相对路径...
回答by RobDigital
If you are running a PHP IIS stackand have this error, it is usually a quick permission fix.
如果您正在运行PHP IIS 堆栈并出现此错误,通常是一种快速权限修复。
If you administer the windows server yourself and have access, try this FIRST:
如果您自己管理 Windows 服务器并有权访问,请首先尝试:
Navigate to the folder that is giving you grief on writing to and right click it > open properties > security.
导航到在写入时让您感到悲伤的文件夹,然后右键单击它 > 打开属性 > 安全性。
See what users have access to the folder, which ones have read only and which have full. Do you have a group that is blocking write?
查看哪些用户可以访问该文件夹,哪些是只读的,哪些是完整的。你有一个阻止写入的组吗?
The fix will be specific to your IIS setup, are you using Anonymous Authentication with specific user IUSR or with the Application Pool identity?
该修复将特定于您的 IIS 设置,您是使用特定用户 IUSR 还是应用程序池身份使用匿名身份验证?
At any rate, you are going to end up adding a new full write permission for one of IUSR, IIS_IUSRS, or your application pool identity - like I said, this is going to vary depending on your setup and how you want to do it, you can go down the google rabbit hole on this one (one such post - IIS_IUSRS and IUSR permissions in IIS8) For me, i use anon with my app pool identity so i can get away with MACHINE_NAME\IIS_IUSRSwith full read/write on any temp or upload folders.
无论如何,您最终都会为 IUSR、IIS_IUSRS 或您的应用程序池标识之一添加新的完整写入权限 - 就像我说的,这将根据您的设置和您想要的方式而有所不同,你可以在这个(一个这样的帖子 - IIS8 中的 IIS_IUSRS 和 IUSR 权限)上深入谷歌兔子洞对我来说,我使用 anon 和我的应用程序池标识,这样我就可以MACHINE_NAME\IIS_IUSRS在任何临时或上传上完全读/写文件夹。
I do not need to add anything extra to my open_basedir =in the php.ini.
我不需要open_basedir =在 php.ini 中添加任何额外的东西。
回答by MAChitgarha
In addition to @yogihosting's answer, if you are using DirectAdmin, then follow these steps:
除了@yogihosting 的回答之外,如果您使用的是DirectAdmin,请按照以下步骤操作:
- Go to the DirectAdmin's login page. Usually, its port is 2222.
- Login as administrator. Its username is
adminby default. - From the "Access Level" on the right panel, make sure you are on "Admin Level". If not, change to it.
- From the "Extra Features" section, click on "Custom HTTPD Configurations".
- Choose the domain you want to change.
Enter the configurations you want to change in the textarea at the top of the page. You should consider the existing configuration file and modify values based on it. For example, if you see that
open_basediris set inside a<Directory>, maybe you should surround your change in the related<Directory>tag:<Directory "/path/to/directory"> php_admin_value open_basedir none </Directory>After making necessary changes, click on the "Save" button.
- You should now see your changes saved to the configuration file if they were valid.
- 转到 DirectAdmin 的登录页面。通常,它的端口是 2222。
- 以管理员身份登录。它的用户名是
admin默认的。 - 从右侧面板上的“访问级别”,确保您处于“管理员级别”。如果没有,请更改为它。
- 从“额外功能”部分,单击“自定义 HTTPD 配置”。
- 选择要更改的域。
在页面顶部的文本区域中输入要更改的配置。您应该考虑现有的配置文件并根据它修改值。例如,如果您看到它
open_basedir设置在 a 中<Directory>,也许您应该将您的更改括在相关<Directory>标签中:<Directory "/path/to/directory"> php_admin_value open_basedir none </Directory>进行必要的更改后,单击“保存”按钮。
- 如果更改有效,您现在应该会看到已保存到配置文件中的更改。
There is another way of editing the configuration file, however:
但是,还有另一种编辑配置文件的方法:
Caution: Be careful, and use the following steps at your own risk, as you may run into errors, or it may lead to downtime. The recommended way is the previous one, as it prevents you from modifying configuration file improperly and show you the error.
注意: 请小心,并自担风险使用以下步骤,因为您可能会遇到错误,或者可能导致停机。推荐的方式是前一种,因为它可以防止您不正确地修改配置文件并显示错误。
- Login to your server as root.
- Go to
/usr/local/directadmin/data/users. From the listed users, go to one related to the domain you want to change. Here, there is an
httpd.conffile. Make a backup from it:cp httpd.conf httpd.conf.backNow edit the configuration file with your editor of choice. For example, edit existing
open_basedirtonone. Do not try to remove things, or you may experience downtime. Save the file after editing.Restart the Apache web server using one of the following ways (use
sudoif needed):httpd -k graceful apachectl -k graceful apache2 -k gracefulIf your encounter any errors, then replace the main configuration file with the backed-up file, and restart the web server.
- 以 root 身份登录到您的服务器。
- 去
/usr/local/directadmin/data/users。从列出的用户中,转到与您要更改的域相关的用户。 在这里,有一个
httpd.conf文件。从中备份:cp httpd.conf httpd.conf.back现在使用您选择的编辑器编辑配置文件。例如,将现有编辑
open_basedir为none. 不要试图删除东西,否则您可能会遇到停机时间。编辑后保存文件。使用以下方式之一重新启动 Apache Web 服务器(
sudo如果需要,请使用):httpd -k graceful apachectl -k graceful apache2 -k graceful如果遇到任何错误,请将主配置文件替换为备份文件,然后重新启动 Web 服务器。
Again, the first solution is the preferred one, and you should not try the second method at the first time. As it is noted in the caution, the advantage of the first way is that it prevents saving your bad-configured stuff.
同样,第一种解决方案是首选方法,您不应该在第一次尝试第二种方法。正如警告中所指出的,第一种方法的优点是它可以防止保存错误配置的东西。
Hope it helps!
希望能帮助到你!
回答by Fanax
I am using an Apache vhost-File to run PHP with application-specific ini-options on my windows-server. Therefore I use the -doption of the php-command.
我正在使用 Apache vhost-File 在我的 Windows 服务器上运行带有特定于应用程序的 ini 选项的 PHP。因此我使用php 命令的-d选项。
I am setting the open_basedirfor every application as one of these options.
我将每个应用程序的open_basedir设置为这些选项之一。
I needed to set multiple urls as open_basedir, including an UNC-Path, and the syntax for this case was a bit hard to find. You have to seperate the paths with semicolonsand if your first path starts with a driveletter you might have to start the list with a semicolon too. At least that's what works for me.
我需要将多个 url 设置为 open_basedir,包括一个UNC-Path,并且这种情况的语法有点难以找到。您必须用分号分隔路径,如果您的第一个路径以驱动器字母开头,您可能也必须以分号开头。至少这对我有用。
Example:
例子:
php.exe -d open_basedir=;d:/www/applicationRoot;//internal.unc.path/ressource/


