I got “Failed to open stream: Permission denied” when the PHP script attempts to write a file.
Quick and easy fix, you need to give write permission to IUSR and IIS AppPool\AppPoolName, for my application I just need to set the writing permission for the IUSR user, but you might need to set the IIS AppPool\AppPoolName for your application too. Please read the EXPLANATION for more detail.
1. Check for fastcgi impersonate:
Create a test file to show up the value of fastcgi impersonate
<?php var_dump(ini_get('fastcgi.impersonate')); ?>
2. If the value is 1:
Open your command line (run as Administrator) to see what’s the userName for anonymousAuthentication
%windir%\system32\inetsrv\appcmd.exe list config “Default Web Site” /section:anonymousAuthentication
The answer is similar to this
<anonymousAuthentication enabled="true" userName="IUSR" />
Check the value of userName:
- If userName is not empty, then its value is the user for setting the write permission
- if userName is missing/empty, you need to give write permission for IIS AppPool\AppPoolName (you should replace AppPoolName with the name of your website’s application pool)
3. If the value is 0:
You need to give write permission for IIS AppPool\AppPoolName (you should replace AppPoolName with the name of your website’s application pool)