由于只读属性,PHP mkdir 权限被拒绝在 Windows Server 2008 IIS 7 上运行? [英] PHP mkdir Permission Denied running on Windows Server 2008 IIS 7 due to Read Only Attribute?

查看:20
本文介绍了由于只读属性,PHP mkdir 权限被拒绝在 Windows Server 2008 IIS 7 上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows Server 2008 上的 IIS 7 上运行 PHP 网站时遇到问题.

I'm having a problem with a PHP website running on IIS 7 on Windows Server 2008.

有一行代码调用 mkdir 出错,错误日志如下:

There is one line of code calling mkdir which is erroring and the error log reads:

...权限被拒绝..."

"... permission denied ..."

我已经排除了与文件夹权限有关的任何事情(我尝试了多个组:所有人、用户、IUSR、网络服务等,但都没有成功).

我需要知道 mkdir 是如何工作的,它会检查父文件夹的只读属性吗?

如果是这样,那么这可能是问题的根源,因为 Windows Server 2008 中的所有文件夹都被标记为只读"并且复选框是灰色的 - 微软说这是设计使然",但我认为它是真是糟糕的设计".

If so, then this could be the root of the problem as all folders in Windows Server 2008 are marked as "Read Only" and the checkbox is greyed-out - Microsoft say it is "by design" but I think it is really "bad design".

请帮忙.

附言可以在此处找到错误的代码行 https://github.com/LimeSurvey/LimeSurvey/blob/070d255ba381d7abcd231d7c9e0c7d11f5578c97.com/LimeSurvey/LimeSurvey/blob/070d255ba381d7abcd231d7c9e0c7d11f5578c97/admin/templates.php#L1182 这是第 1182 行.

P.S. The line of code which errors can be found here https://github.com/LimeSurvey/LimeSurvey/blob/070d255ba381d7abcd231d7c9e0c7d11f5578c97/admin/templates.php#L1182 it is line 1182.

解决方案:

  • 毕竟是权限问题!
  • 我们对错误的文件夹应用了权限(用手拍额头)
  • 有两个模板"文件夹:/Templates 和/Uploads/Templates
  • /Template 用于默认模板,而/Uploads/Templates 用于用户创建的模板
  • 我们授予用户"组对/Uploads/Templates 文件夹的 r/w/execute/modify 权限
  • 而之前我们将权限应用于/Templates
  • 为了调试这个,我使用了 echo 来输出 $target
  • It was a permissions issue after all!
  • We were applying permissions to the wrong folder (smacks hand to forehead)
  • There are two "Templates" folders: /Templates and /Uploads/Templates
  • /Template is for default templates whereas /Uploads/Templates is for user-created ones
  • We gave the "Users" group r/w/execute/modify permissions to /Uploads/Templates folder
  • Whereas previously we were applying permissions to /Templates
  • To debug this I used echo to output the $target value

经验教训:

  • 总是阅读错误消息 - 它说权限被拒绝",我不相信
  • 不要假设明显是真的 -/Templates 不是正确的文件夹
  • 如果代码出错,请调试代码,不要试图猜测问题
  • 使用简单的技术调试代码,例如输出变量值 - 例如回声
  • 听听大多数人的意见 - 这里的大多数人说这是一个权限问题是正确的!
  • 大多数错误都有一个简单的修复方法 - 不要去寻找复杂的东西

由于 mkdir() 文档中的有用引述,@BOMEz 获得了赏金,这表明我应该仔细考虑权限.@BOMEz 还提供了量身定制的答案,并通过评论与我互动,这很有帮助.

Bounty awarded to @BOMEz because of the useful quote from mkdir() documentation which indicated that I should double-think the permissions. @BOMEz also provided a tailored answer and interacted with me via comments which helped.

推荐答案

  • 作为测试(最好在开发环境中),授予 IIS 用户对父文件夹的完全访问权限.如果这样可以奏效,请慢慢开始取消权限以查看您需要哪些权限.

    • As a test (preferably in a development environment) give the IIS user full access to the parent folder. If this makes it work, slowly start taking away privileges to see which ones you need.

      尝试改变:

      if(mkdir($target,0777))

      到:

      if(mkdir($target))

      Windows 忽略模式选项.可能是一些奇怪的错误导致它失败.

      Windows ignores the mode option. Might be some weird bug causing it to fail.

      另外,对于您的 $target 变量,您可以尝试强制它链接到完整的 Windows 路径吗?如C:Program FilesIIS...

      Additionally for your $target variable could you try forcing it to link to the full Windows path? Such as C:Program Files IIS...

      在尝试使用相对路径时访问被拒绝的 Windows 情况之前,我曾遇到过这种情况,但完整路径工作正常.

      I've ran into situations with windows before where access was denied attempting to use a relative path, but the full path works just fine.

      查看对 mkdir() 文档的评论,一位评论者提到您可能还需要为用户添加执行权限:

      Looking at the comments on the documentation for mkdir() one commenter mentions that you might also need to add execute permissions to the user:

      如果您收到 Permission Denied 错误,但确定您尝试创建目录的权限和所有权是正确的,再次检查:

      If you're getting a Permission Denied error, but are certain the permissions and ownership where you are trying to create the directory are correct, check again:

      您尝试在其中创建目录的位置必须具有尝试创建它的所有者的执行权限,无论文件夹是否可读或可写.

      The location where you are trying to create the directory in must have the Execute permission for the owner trying to create it, regardless of if the folder is Readable, or Writable.

      这对某些人来说可能很明显,但一开始对我来说不是.希望这样可以省去我遇到的麻烦.

      This may be obvious to some, but was not to me at first. Hopefully this will save you the trouble I went through.

      这篇关于由于只读属性,PHP mkdir 权限被拒绝在 Windows Server 2008 IIS 7 上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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