open_basedir 限制生效。文件(/)不在允许的路径内:

发布于 2024-08-13 02:24:44 字数 212 浏览 4 评论 0原文

我在网站上上传头像时遇到此错误。我以前从未得到过它,并且最近没有任何更改让我开始收到此错误......

Warning: is_writable() [function.is-writable]: 
open_basedir restriction in effect. 
File(/) is not within the allowed path(s):

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):

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(22

守护在此方 2024-08-20 02:24:44

修改您的托管帐户中的 open_basedir 设置并将其设置为 none。找到 Plesk/cPanel 的“PHP 设置”区域下给出的 open_basedir 设置。从那里给出的下拉列表中将其设置为“无”。
我已经在 Plesk 面板图片中展示了它们。

在此处输入图像描述
在此处输入图像描述

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.

enter image description here
enter image description here

柏拉图鍀咏恒 2024-08-20 02:24:44

要解决此错误,您必须编辑文件 httpd.conf。
之前可以在 phpinfo 中的 apache2handler 部分指令 Server Root 中看到。
例如我的例子是这样的——/etc/httpd/httpd.conf。
打开文件httpd.conf,找到参数open_basedir。并将其设置为无。 (php_admin_value open_basedir 无)

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)

我也只是我 2024-08-20 02:24:44

如果您使用 php file.php 运行此程序。您需要编辑php.ini
找到此文件:

: locate php.ini
/etc/php/php.ini

并将文件的路径附加到 open_basedir 属性:

open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share /webapps/:/etc/webapps/:/run/media/andrew/ext4/protected

If you're running this with php file.php. You need to edit php.ini
Find this file:

: locate php.ini
/etc/php/php.ini

And append file's path to open_basedir property:

open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/:/run/media/andrew/ext4/protected

回眸一遍 2024-08-20 02:24:44

Laravel

如果你在使用 Laravel 时遇到这个问题。

只需转到文件夹 bootstrap/cache 并将 config.php 重命名为您想要的任何内容,然后重新加载站点。

Laravel

If you have this problem when using Laravel.

Only go to folder bootstrap/cache and rename config.php to anything you want and reload site.

梦途 2024-08-20 02:24:44

对我来说,问题是运行整个过程的 Plesk 服务器的配置值错误/丢失。
我只是按照这里的指示操作:
http://davidseah.com/blog/2007 /04/separate-php-error-logs-for-multiple-domains-with-plesk/

您可以将 PHP 配置为每个 VirtualHost 定义都有一个单独的错误日志文件。诀窍是确切地知道如何设置它,因为您无法在不破坏 Plesk 的情况下直接更改配置。
(dv) 上的每个域名在 /var/www/vhosts 中都有自己的目录。典型的目录具有以下顶级目录:

cgi-bin/
conf/
error_docs/
httpdocs/
httpsdocs/
...and so on

您需要在域目录的 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

更改第一个值以匹配您的实际安装(我使用 /tmp/phperrors.conf)日志)。编辑完 vhost.conf 文件后,从控制台测试配置:

apachectl configtest
…or if you don’t have apachectl (as Plesk 8.6 doesn’t seem to)…

/etc/init.d/httpd configtest

最后告诉 Plesk 您已进行此更改。

/usr/local/psa/admin/bin/websrvmng -a

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/

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:

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:

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:

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.

/usr/local/psa/admin/bin/websrvmng -a
来日方长 2024-08-20 02:24:44

更新和/或移动后,我在我的 WordPress 网站之一遇到了这个问题。

检查数据库表“wp_options”的“upload_path”并正确编辑它...

I had this problem @ one of my wordpress sites after updating and/or moving.

Check in database table 'wp_options' the 'upload_path' and edit it properly...

默嘫て 2024-08-20 02:24:44

如果使用ispconfig3:

转到网站部分 ->选项-> PHP open_basedir:

“在此处输入图像描述”

  • 在此字段中描述了允许的路径,并且每个路径都是分开的
    和 ”:”

/var/www/clients/client2/web3/image:/var/www/clients/client2/web3/web:/var/www/...
等等

  • 所以这里必须放置您想要访问的路径,在我的例子中是:

/var/www/clients/client2/web3/image:

  • 出现问题的原因是:

当脚本尝试访问文件系统时(例如使用 include 或 fopen()),将检查文件的位置。当文件位于指定的目录树之外时,PHP 将拒绝访问它。

If used ispconfig3:

Go to Website section -> Options -> PHP open_basedir:

enter image description here

  • In this field has described allowed paths and each path is separated
    with ":"

/var/www/clients/client2/web3/image:/var/www/clients/client2/web3/web:/var/www/...
and so on

  • So here must put the path that you want to have access, in my case is:

/var/www/clients/client2/web3/image:

  • The problem appears because:

When a script tries to access the filesystem, for example using include, or fopen(), the location of the file is checked. When the file is outside the specified directory-tree, PHP will refuse to access it.

彻夜缠绵 2024-08-20 02:24:44

编辑位于主目录中的 php.ini 或 .user.ini

open_basedir = none

Edit the php.ini or .user.ini that is located within the main directory

open_basedir = none
同展鸳鸯锦 2024-08-20 02:24:44

您引用的路径不正确,并且不在工作区的目录根范围内。尝试构建您要访问的文件的绝对路径,您现在可能正在使用相对路径...

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...

鹤舞 2024-08-20 02:24:44

我在使用 ispconfig3 时遇到了这种问题,并收到了这样的错误

open_basedir 限制生效。
文件(/var/www/clients/client7/web15)不在允许范围内
路径:........................

为了解决我的情况,我只需在 ispconfig3 的网站面板中将 PHP 设置为 SuPHP

I had this kind of problem with ispconfig3 and got an error like this

open_basedir restriction in effect.
File(/var/www/clients/client7/web15) is not within the allowed
path(s):.........

To solve it in my case, I just set PHP to SuPHP in the Website's panel of ispconfig3

拿命拼未来 2024-08-20 02:24:44

如果您正在运行 PHP IIS 堆栈并遇到此错误,通常可以快速进行权限修复。

如果您自己管理 Windows 服务器并有权访问,请首先尝试此操作:

导航到使您在写入时感到痛苦的文件夹,然后右键单击它 > >打开属性>安全。

查看哪些用户有权访问该文件夹,哪些用户具有只读权限,哪些用户具有完整权限。您是否有一个组阻止写入?

该修复将特定于您的 IIS 设置,您是否使用特定用户 IUSR 或应用程序池身份的匿名身份验证?

无论如何,您最终都会为 IUSR、IIS_IUSRS 或您的应用程序池标识之一添加新的完全写入权限 - 就像我说的,这将根据您的设置以及您想要的方式而有所不同,你可以在这个问题上深入谷歌兔子洞(一篇这样的帖子 - IIS_IUSRS 和IIS8 中的 IUSR 权限)对我来说,我将 anon 与我的应用程序池身份一起使用,这样我就可以使用 MACHINE_NAME\IIS_IUSRS 对任何临时或上传文件夹进行完全读/写。

我不需要向 php.ini 中的 open_basedir = 添加任何额外内容。

If you are running a PHP IIS stack and have this error, it is usually a quick permission fix.

If you administer the windows server yourself and have access, try this FIRST:

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?

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_IUSRS with full read/write on any temp or upload folders.

I do not need to add anything extra to my open_basedir = in the php.ini.

一身骄傲 2024-08-20 02:24:44

除了@yogihosting的回答之外,如果您使用DirectAdmin,请按照以下步骤

  1. 操作 :到 DirectAdmin 的登录页面。通常,其端口为2222。
  2. 以管理员身份登录。默认情况下,其用户名是admin
  3. 从右侧面板上的“访问级别”,确保您处于“管理员级别”。如果没有,请更改为它。
  4. 从“额外功能”部分,单击“自定义 HTTPD 配置”。
  5. 选择您要更改的域。
  6. 在页面顶部的文本区域中输入您要更改的配置。您应该考虑现有的配置文件并根据它修改值。例如,如果您发现 open_basedir 设置在 内,也许您应该将您的更改包含在相关的 中> 标签:

    <目录“/path/to/directory”>
        php_admin_value open_basedir 无
    
    
  7. 进行必要的更改后,单击“保存”按钮。

  8. 如果更改有效,您现在应该会看到已保存到配置文件中的更改。

不过,还有另一种编辑配置文件的方法:

警告:请务必小心,并自行承担使用以下步骤的风险,因为您可能会遇到错误,或者可能导致停机。推荐的方法是前一种,因为它可以防止您错误地修改配置文件并显示错误。

  1. 以 root 身份登录到您的服务器。
  2. 转到/usr/local/directadmin/data/users。从列出的用户中,转到与您要更改的域相关的用户。
  3. 这里有一个httpd.conf 文件。从中进行备份:

    cp httpd.conf httpd.conf.back
    
  4. 现在使用您选择的编辑器编辑配置文件。例如,将现有的 open_basedir 编辑为 none。不要尝试删除任何东西,否则您可能会遇到停机。编辑后保存文件。

  5. 使用以下方法之一重新启动 Apache Web 服务器(如果需要,请使用 sudo):

    httpd -k 优雅
    apachectl -k 优雅
    apache2 -k 优雅
    
  6. 如果遇到任何错误,请将主配置文件替换为备份文件,然后重新启动 Web 服务器。

再次强调,第一个解决方案是首选,您不应该在第一次尝试第二种方法。正如警告中所指出的,第一种方法的优点是它可以防止保存错误配置的内容。

希望有帮助!

In addition to @yogihosting's answer, if you are using DirectAdmin, then follow these steps:

  1. Go to the DirectAdmin's login page. Usually, its port is 2222.
  2. Login as administrator. Its username is admin by default.
  3. From the "Access Level" on the right panel, make sure you are on "Admin Level". If not, change to it.
  4. From the "Extra Features" section, click on "Custom HTTPD Configurations".
  5. Choose the domain you want to change.
  6. 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_basedir is 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>
    
  7. After making necessary changes, click on the "Save" button.

  8. You should now see your changes saved to the configuration file if they were valid.

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.

  1. Login to your server as root.
  2. Go to /usr/local/directadmin/data/users. From the listed users, go to one related to the domain you want to change.
  3. Here, there is an httpd.conf file. Make a backup from it:

    cp httpd.conf httpd.conf.back
    
  4. Now edit the configuration file with your editor of choice. For example, edit existing open_basedir to none. Do not try to remove things, or you may experience downtime. Save the file after editing.

  5. Restart the Apache web server using one of the following ways (use sudo if needed):

    httpd -k graceful
    apachectl -k graceful
    apache2 -k graceful
    
  6. If your encounter any errors, then replace the main configuration file with the backed-up file, and restart the web server.

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!

用心笑 2024-08-20 02:24:44

我正在使用 Apache vhost-File 在 Windows 服务器上运行带有特定于应用程序的 ini 选项的 PHP。因此我使用 php 命令的 -d 选项。

我为每个应用程序设置 open_basedir 作为这些选项之一。

我需要将多个 url 设置为 open_basedir,包括 UNC-Path,并且这种情况的语法有点难以找到。您必须用分号分隔路径,如果您的第一个路径以驱动器盘符开头,您可能也必须以分号开始列表。至少这对我有用。

例子:

php.exe -d open_basedir=;d:/www/applicationRoot;//internal.unc.path/ressource/

I am using an Apache vhost-File to run PHP with application-specific ini-options on my windows-server. Therefore I use the -d option of the php-command.

I am setting the open_basedir for every application as one of these options.

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 semicolons and 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.

Example:

php.exe -d open_basedir=;d:/www/applicationRoot;//internal.unc.path/ressource/
怂人 2024-08-20 02:24:44

我在 Directadmin 面板上上传了我的 codeigniter 项目。我遇到了同样的错误。
错误

然后我更改 php 设置。

open_basedir =
session.save_path = ./temp/

然后它对我有用。

I uploaded my codeigniter project on Directadmin panel. I was getting same error.
error

Then I change in php settings.

open_basedir =
session.save_path = ./temp/

Then it worked for me.

永不分离 2024-08-20 02:24:44

由于大多数人都没有找到解决方案,因此 WordPress 的解决方案很广泛,大多数人甚至不完全知道为什么会这样。

我发现你必须为你的服务器启用 IP,特别是在使用 Cerber 时,在某些情况下它可能会认为你没有上传 .png,而是上传 .js 文件。

服务器IP需要加入白名单。在极少数情况下,甚至上传者也是如此。

很高兴知道的是在您的基本目录中有一个 tmp 文件夹 755,您实际上不需要一个名为 tmp 的文件夹。:“另请记住/正确编辑如下:

open_basedir = "/home/user/site.com/:/tmp"
upload_tmp_dir = /home/user/site.com/tmp

快速设置的最佳选项是在使用 MultiPHP 的 Cpanel 中您实际上可以保存 INI 编辑器,并且 .htaccess 和 php.ini 都将被更新,并且站点上同时启动设置。

不建议将 basedir 设置为“none”,因为您正在启用可编辑的根文件。如果这真的可能的话,只需在 WordPress 中使用一个文件编辑器即可。

As most do not find a solution, the solutions are broad for WordPress most even don't know fully why things are they are.

I've found out you will have to enable IP for your server in especially when using Cerber in some cases it can think you are not uploading .png instead you are uploading .js files.

The server IP needs to be whitelisted. Even the uploaders in some rare cases.

A great to know is to have a tmp folder 755 in your base directory, you actually do not need a folder called tmp.: "Also remember / properly inedited as below:

open_basedir = "/home/user/site.com/:/tmp"
upload_tmp_dir = /home/user/site.com/tmp

The best option for quick setup is in Cpanel where you use the MultiPHP INI Editor you can actually save and both .htaccess and php.ini will be updated as well as settings being initiated at the same time on site.

It's NOT recommended to have basedir as "none" since you are enabling root files that can be edited with just a single file editor in WordPress. If that truly is possible.

天暗了我发光 2024-08-20 02:24:44

对我来说,这是因为我在 php.ini 的 tmp 目录中给出了错误的路径。

希望这有帮助

For me it is because I gave the wrong path in the tmp directory of php.

Hope this helps

薄荷→糖丶微凉 2024-08-20 02:24:44

当我使用 Imagick 将图像转换为 .avif 格式时,出现此错误。

$image = new Imagick();
$image->readImage('input.jpeg'); // got error here
...

解决方案是使用 __DIR__,如下所示:

$image->readImage(__DIR__ . '/input.jpeg');

我希望它可以帮助某人。

I got this error when I used Imagick for converting image to .avif format.

$image = new Imagick();
$image->readImage('input.jpeg'); // got error here
...

Solution was to use __DIR__, like this:

$image->readImage(__DIR__ . '/input.jpeg');

I hope it helps someone.

凶凌 2024-08-20 02:24:44

如果使用 cPanel,请选择“选择 PHP 版本”> “选项”

用冒号 (:) 分隔的所有允许的目录更新 open_basedir。

例如:/home/website/public_html:/home/website/config

我遇到此问题是因为我在 cPanel 帐户中使用了第二个域。当我在第二个域上安装 wordpress 时,它无法访问该目录,直到我更新它。

(仅为了安全起见,半页)

If using cPanel choose "Select PHP Version" > "Options"

Update open_basedir with all allowed directories separated by a colon (:).

ex: /home/website/public_html:/home/website/config

I was having this issue because I was using a second domain in my cPanel account. When I installed wordpress on the second domain, it wasn't able to access the directory until I updated this.

(Only half a page for security)

抱猫软卧 2024-08-20 02:24:44

检查 plesk 中的 \httpdocs\bootstrap\cache\config.php 文件,看看是否有一些不需要的路径。

Check \httpdocs\bootstrap\cache\config.php file in plesk to see if there are some unwanted paths.

笑梦风尘 2024-08-20 02:24:44

只需搜索

open_basedir =

在 php.ini 中并禁用它。这是解决这个问题的最简单的解决方案。

更改前 open_basedir =

更改后 ;open_basedir =

Ps - 更改后不要忘记重新启动服务器。

享受 ;)

Just search

open_basedir =

in php.ini and disable it. That's the simplest solution to solve this issue.

Before Changes open_basedir =

After Changes ;open_basedir =

P.s - After changes don't forget to restart your server.

Enjoy ;)

花落人断肠 2024-08-20 02:24:44

修改 open_basedir 设置< /a> 在您的 PHP 配置中(请参阅运行时配置)。

open_basedir 设置主要用于防止特定用户的 PHP 脚本访问其他用户帐户中的文件。因此,通常情况下,您自己帐户中的任何文件都应该可由您自己的脚本读取。

如果 PHP 在 Linux 系统上作为 Apache 模块运行,则通过 .htaccess 设置示例:

<DirectoryMatch "/home/sites/site81/">
    php_admin_value open_basedir "/home/sites/site81/:/tmp/:/"
</DirectoryMatch>

Modify the open_basedir settings in your PHP configuration (See Runtime Configuration).

The open_basedir setting 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.

Example settings via .htaccess if PHP runs as Apache module on a Linux system:

<DirectoryMatch "/home/sites/site81/">
    php_admin_value open_basedir "/home/sites/site81/:/tmp/:/"
</DirectoryMatch>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文