在 IIS 7 上为 PHP 添加写入权限

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5887131/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:48:17  来源:igfitidea点击:

Add writing permission to PHP on IIS 7

phpiis-7windows-server-2008file-permissions

提问by JuCachalot

I need a PHP script to have writing permission in a directory. PHP 5.3 is running as FastCGI under IIS 7 with windows server 2008 as OP. On my php error logs, I got "permission denied" when the script attempts to write a file.

我需要一个 PHP 脚本才能在目录中拥有写入权限。PHP 5.3 在 IIS 7 下作为 FastCGI 运行,Windows Server 2008 作为 OP。在我的 php 错误日志中,当脚本尝试写入文件时,我收到了“权限被拒绝”的消息。

How can I sort this out? I tried to give all right to IIS_IUSR and to IUSR_myservername (with a right click on my folder) but it didn't work.

我该如何解决这个问题?我试图授予 IIS_IUSR 和 IUSR_myservername 的所有权限(右键单击我的文件夹),但没有奏效。

Any help would be very appreciate,

任何帮助将不胜感激,

Regards,

问候,

Julien

于连

回答by tomfumb

I have the same setup and I have to give write permission to:

我有相同的设置,我必须给予写权限:

  • IUSR
  • IIS AppPool\<<AppPoolName>>
  • IUSR
  • IIS AppPool\<<AppPoolName>>

回答by Tristan CHARBONNIER

Actually, it's a little bit more complicated.

实际上,它有点复杂。

The first thing to do is to create a simple PHP file on the concerned website. (It's important to create the file on the concerned website because each website can have a different setting.) The content of this file should be:

首先要做的是在相关网站上创建一个简单的 PHP 文件。(在相关网站上创建文件很重要,因为每个网站可以有不同的设置。)该文件的内容应该是:

<?php var_dump(ini_get('fastcgi.impersonate')); ?>

Navigate to this file using a browser.

使用浏览器导航到此文件。

** Case 1 **

** 情况1 **

If your browser shows :

如果您的浏览器显示:

string(1) "1"

Then, you need to execute the following command (you need to replace "Default Web Site" by the name you gave to your website in IIS) :

然后,您需要执行以下命令(您需要将“默认网站”替换为您在 IIS 中为您的网站提供的名称):

%windir%\system32\inetsrv\appcmd.exe list config "Default Web Site" ^
/section:anonymousAuthentication

You will receive an answer which looks like this :

您将收到如下所示的答案:

<system.webServer>
  <security>
    <authentication>
      <anonymousAuthentication enabled="true" userName="IUSR" />
    </authentication>
   </security>
</system.webServer>

The information you are looking for is the value of the usernameattribute of the anonymousAutthentificationtag.

您要查找的信息是标签的username属性值anonymousAutthentification

  • If this value is not empty, its content is the name of the user you need to give write permissions to.
  • If this value is empty or if the attribute is simply missing, you need to give write permissions to IIS AppPool\AppPoolName(replace "AppPoolName" with the name of your website's application pool).
  • 如果此值不为空,则其内容是您需要为其授予写入权限的用户的名称。
  • 如果此值为空或该属性只是缺失,则您需要授予写入权限IIS AppPool\AppPoolName(将“AppPoolName”替换为您网站的应用程序池的名称)。

** Case 2 **

** 案例 2 **

If your browser shows :

如果您的浏览器显示:

string(1) "0"

You need to give write permissions to IIS AppPool\AppPoolName(replace "AppPoolName" with the name of your website's application pool).

您需要授予写入权限IIS AppPool\AppPoolName(将“AppPoolName”替换为您网站的应用程序池的名称)。

回答by Andrea

You need to give PHPwriting permission, not IIS. This means the user account that PHP is running on needs permission (probably the same one IIS is running on).

您需要授予PHP写入权限,而不是 IIS。这意味着运行 PHP 的用户帐户需要权限(可能是运行 IIS 的用户帐户)。