简体   繁体   English

在IIS上调试PHP错误(因为它与调用com对象有关)

[英]Debugging PHP error on IIS (as it relates to calling com objects)

This question is related to another question I wrote: 这个问题与我写的另一个问题有关:

Trouble using DOTNET from PHP. 使用PHP的DOTNET时出现问题。

Where I was using the DOTNET() function in PHP to call a DLL I had written. 我在PHP中使用DOTNET()函数调用我编写的DLL的位置。

I was able to get it working fine by running php.exe example.php from the command line (with the DLL's still in the PHP folder). 通过从命令行运行php.exe example.php (DLL仍位于PHP文件夹中),我能够使其正常运行。

I moved the php file to an IIS 7 webserver folder on the same machine (leaving the DLLs in the same php folder), but I keep getting a 500 internal service error . 我将php文件移动到同一台机器上的IIS 7 Web服务器文件夹中(将DLL保留在同一php文件夹中),但是我不断收到500内部服务错误

I've checked the server logs (in c:\\inetput\\logs\\ and in c:\\windows\\temp\\php53errors ) but there doesn't seem to be any relevant information about what caused the error. 我已经检查了服务器日志(在c:\\inetput\\logs\\c:\\windows\\temp\\php53errors ),但是似乎没有任何有关导致此错误的信息。 I even tried to change the php.ini settings to get more error feedback, but that doesn't seem to help. 我什至尝试更改php.ini设置以获取更多错误反馈,但这似乎无济于事。

I can only guess that the issue may be related to: 我只能猜测该问题可能与以下方面有关:

  1. that php file not having the proper permissions (my dll does some file reading/writing) 该php文件没有适当的权限(我的dll执行某些文件读取/写入操作)
  2. php can't find the DLLs php找不到DLL

The actual error I get is: 我得到的实际错误是:

The FastCGI process exited unexpectedly. FastCGI进程意外退出。

Any idea on how to debug this problem? 关于如何调试此问题的任何想法?

The problem here is almost certainly related to file permissions. 这里的问题几乎可以肯定与文件权限有关。

When you run php.exe from the command line you run as your own logged-in user. 当您从命令行运行php.exe ,您将以自己的登录用户身份运行。 When running a PHP script from IIS, in response to an http request, php.exe runs as a different user. 当从IIS运行PHP脚本时,作为对http请求的响应,php.exe将以其他用户身份运行。 Depending on your version of Windows it could be 根据您的Windows版本,可能是

  • IUSR_machine - on IIS6 and prior IUSR_machine在IIS6及IUSR_machine
  • IUSR on IIS7 and later IIS7和更高版本上的IUSR

These users need permissions on the php file to be executed. 这些用户需要对php文件的权限才能执行。

Read more about it 进一步了解

On IIS7 and later I use a command-line tool called icacls.exe to set the permissions on directories or files that need to be read by IIS and the processes it starts (like php.exe). 在IIS7及更高版本上,我使用名为icacls.exe的命令行工具来设置对IIS及其启动进程(如php.exe)需要读取的目录或文件的权限。 This security stuff applies to all IIS applications: PHP, ASPNET, ASP-classic, Python, and so on. 此安全性内容适用于所有IIS应用程序:PHP,ASPNET,ASP-classic,Python等。

IIS also needs to be able to read static files, like .htm, .js, .css, .jpog, .png files and so on. IIS还需要能够读取静态文件,例如.htm,.js,.css,.jpog,.png文件等。 You can set the same permissions for all of them: Read and Execute. 您可以为所有它们设​​置相同的权限:“读取”和“执行”。

You can grant permissions directly to the user, like this: 您可以直接向用户授予权限,如下所示:

 icacls.exe  YOUR-FILE-GOES-HERE  /grant "NT AUTHORITY\IUSR:(RX)"

You can also grant permissions to the group, to which IUSR belongs, like this: 您还可以向IUSR所属的组授予权限,如下所示:

 icacls.exe YOUR-FILE-HERE  /grant "BUILTIN\IIS_IUSRS:(RX)"

In either case you may need to stop and restart IIS after setting file-level permissions. 在这两种情况下,您可能都需要在设置文件级权限后停止并重新启动IIS。

If your .php script reads and writes other files or directories, then the same user needs pernissions on those other files and directories. 如果您的.php脚本读取和写入其他文件或目录,则同一用户需要对那些其他文件和目录具有震撼力。 If you need the .php script to be able to delete files, then you might want 如果您需要.php脚本才能删除文件,则可能需要

 icacls.exe YOUR-FILE-HERE  /grant "BUILTIN\IIS_IUSRS:(F)"

...which grants full rights to the file. ...授予该文件的完整权限。

You can grant permissions on an entire directory, too, specifying that all files created in that directory in the future will inherit the file-specific permissions set on the directory. 您也可以授予整个目录的权限,指定将来在该目录创建的所有文件都将继承在该目录上设置的特定于文件的权限。 For example, set the file perms for the directory, then copy a bunch of files into it, and all the files get the permissions from the parent. 例如,设置目录的文件权限,然后将一堆文件复制到其中,所有文件都从上级获得权限。 Do this with the OI and CI flags (those initials stand for "object-inherit" and "container-inherit"). 使用OI和CI标志(这些缩写代表“对象继承”和“容器继承”)来执行此操作。

 icacls.exe DIRECTORY  /grant "BUILTIN\IIS_IUSRS:(OI)(CI)(RX)"
 copy FILE1 DIRECTORY
 copy FILE2 DIRECTORY
   ...

When I want to create a new vdir in IIS, to allow running PHP scripts, or ASPX or .JS (yes, ASP Classic) or Python or whatever, I do these steps: 当我想在IIS中创建新的vdir时,以允许运行PHP脚本,ASPX或.JS(是的,ASP Classic)或Python或其他任何东西时,请执行以下步骤:

appcmd.exe add app /site.name:"Default Web Site" /path:/vdirpath /physicalPath:c:\docroot
icacls.exe DIRECTORY  /grant "BUILTIN\IIS_IUSRS:(OI)(CI)(RX)"

Then I drop files into the directory, and they get the proper permissions. 然后,我将文件放到目录中,它们会获得适当的权限。

Setting the ACL (access control list) on the directory will not change the ACL for the files that already exist in the directory. 在目录上设置ACL(访问控制列表)不会更改目录中已存在文件的ACL。 If you want to set permissions on the files that are already in the directory, you need to use icacls.exe on the particular files. 如果要对目录中已存在的文件设置权限,则需要对特定文件使用icacls.exe。 icacls accepts wildcards, and it also has a /t switch that recurses. icacls接受通配符,并且还具有递归的/t开关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM