Permission Denied – PHP On IIS

Hello there,

Have you ever tried to upload a file with php on IIS? or maybe just copy or create a file on a certain folder? Well, I’ve been trying to do that for a while, but it was returning:


Warning: [function] - Permission denied in [my code].

On Windows Server 2003, it’s not an issue and the user can figure out the solution easily by opening the properties of the folder and working with the security tab which I’ll explain later on.

On the other hand, Windows XP users have that security tab hidden. I kept on unchecking the Read-Only, but it was rechecked automatically! The trick is to show the Security Tab in the properties window of the folder. Windows XP have this option hidden; to show it follow the following procedure:

- Open My Computer
- Tools > Folder Options
- Go to the View tab
- In the bottom of the list uncheck “Use simple file sharing (Recommended)”

Now you will have the security tab shown in the properties of every folder. Now, to give write access to PHP in order to fopen, copy or upload a file, follow this procedure:

- Right click on the folder where you want give write access
- Properties
- Go to the Security tab
- Select the Internet Guest Account ([username]/IUSR_[username])
- Allow the Write and Modify access. (You can give full permission)
- Then press Ok.

Your write access should be working by now. Happy coding!

41 Responses to “Permission Denied – PHP On IIS”

  1. Roland says:

    Is theres a way to set this permission through FTP?

  2. masima says:

    This entry was useful very much. Thank you.

    from Japan.

  3. Tim says:

    Fusion,

    I had such high hopes when I encountered your post. And although I did activate the Security tab in XP, and set the permissions for IUSR_… , still it does not work. I can read local files, but I can not touch them.

    Any more tricks up your sleeve?

    • Tim says:

      OMG … I was trying to create an invalid file name.

      Always look for the simple explanation, eh? :-)

  4. sameer says:

    Very useful post. :)
    Thanks!!

  5. nino says:

    Thanks alot

    I am really happy to find the answer..

    once again thank you so much

  6. prabha says:

    Hey..thx for this tip. It did work and got rid of the error!!

  7. Feijão says:

    Thkx!! It’s work’s for me ;)

  8. wild_bill says:

    Excellent post, I’ve been overusing MySql when I should have been using files just because I couldn’t figure this out . . . thanks so much!

  9. par_ten says:

    Thank you very much.

  10. par_ten Thailand says:

    Thank you very much

  11. Jon says:

    Any suggestions for those of us on a shared windows hosting environment? Don’t have access to the server or IIS directly.

    • RedSun says:

      You have to contact your hosting provider, he is the only one who can set it (not possible from your computer).

  12. FetkaN says:

    Thanks man !!!! you rule !!

  13. Biko says:

    Thank you so much for this tip man! Helped me a lot!

  14. Sridhar says:

    Thanks a lot.

  15. John says:

    I had an issue with file upload / write and this solved it. You probably saved me a lot of googling and head scratching.

  16. metaljey says:

    Thank you!
    This is was the other bit of information I needed to get this to work.

    Note: I also added the Authenticated Users with the same permission to the folder. Between setting both groups to the same permissions, I was able to get passed this error.

  17. Ulf Lunde says:

    Thank you!
    Just what I needed!
    Except I had to check Write access for “All”
    before it worked for my ASP.NET VS2005 application
    when not running it in the debugger.

  18. Demola says:

    Like a pain reliever… all my codes got no probs but i kept gettn this stupid access denied error… this post is insightful… i saved this forum for future php problems… once thanks a lot

  19. Adrienne says:

    Hey, just thought I’d let everyone know about a fix I had to do on Windows XP / IIS to resolve this issue:

    Not only did I need to give ISUR_ full control to the files in the project in question, I had to do this:

    - Right-click on the root of the site (for me, that’s a subfolder in wwwroot) and access Properties
    - Go to Security tab
    - Select Internet Guest Account (\ISUR_)
    - Click “Advanced” button
    - Click the “Replace permission entries on all child objects with entries shown here that apply to child objects”
    - Click OK
    - Click OK to the popup warning that says something about how permissions will be replaced (it’s a long, hard to read warning)

    That did it for me, but it could have been because I have been fooling around with permissions for a while and may have screwed something else up previously. But I thought I’d post it just in case it helps someone out there.

    Caveat: This may not work on your machine, and could screw things up. I really don’t know.

  20. Shamsul Akmal Ahmad says:

    Thanks for this valuable tip. I’m having the problem of deleting an existing file. I use PHP5 on IIS5. Now the problem has gone. Thanks very much.

    Kuala Lumpur.

  21. stardog says:

    For me, running XP PRO SP2, my Properties tab was a little different than described, but I finally got it to work.

    1. Right-click, choose Properties.
    2. Select “Sharing” tab.
    3. In “Network sharing and security” section, Check the box “Share this folder on the network.”
    4. Leave the default “Share name”.
    5. Check the box “Allow network users to change my files.”
    6. Click Apply, OK.

  22. Lili says:

    Everything worked fine! Thanks very much! It has prevented me of spending too much time on getting this problem solved!

  23. [...] A blog post on with instructions for changing permissions on Windows 2003 or XP [...]

  24. Kaleem says:

    thanks dude i like it the way ur suggestion helped.

  25. Gadget Man says:

    Thank you so much for sharing this tip. I’ve spent half the day pulling my hair out as to why I kept getting Permission Denied and your solution fixed it within minutes. Many, many thanks.

  26. estonijaan says:

    Followed the instructions exactly only to find that in the “Folder options/view” list there is no option “Use simple file sharing (Recommended)”
    The last option in the list is “Show pop-up description…”

    In another instruction it was said that I should press the key “advanced”, but there is no such key in the view window.

    I have WinXP sp2

    So I am stuck.

    What to do?

  27. Edwardo Eva says:

    Thank you for your help!

  28. Greg says:

    Hi all,
    I lost 1 day working on problem with write permissions on IIS and PHP. I have read number of manuals and make call to other administrators with question for help. I’m 100% sure I did everything right but my test show I have no write permission in target folder via PHP.

    Here is the test code:

    and error:
    PHP Warning: fopen(/test.txt) [function.fopen]: failed to open stream: Permission denied in C:\Inetpub\wwwroot\WriteTest\WriteTest.php on line 5

    line 5 says:
    $testFile = fopen($absUploadFilderPath . ‘/test.txt’, “wt”);

    This error message appear if there is no Uploads folder at all, or there is mistake in relative path (what is same – folder is missing )

    Lesson is test your tests twice and don’t believe 100% on error messages.

    With hope this will save someone headache
    Regards, Greg

  29. c2ckid says:

    The Drupal installer requires that you create a settings file as part of the installation process.

    1. Copy the ./sites/default/default.settings.php file to ./sites/default/settings.php.
    2. Change file permissions so that it is writable by the web server. If you are unsure how to grant file permissions, please consult the on-line handbook.

    More details about installing Drupal are available in INSTALL.txt.

    This is the error I got-can some one please help me to fix it!

  30. Roger says:

    Hey, Folks!I’m getting this error: Permission Denied.I use Windows Server 2003 / PHP 5 Isapi mode.anybody can help me?Please!Thanks

  31. toh.g says:

    I failed in upload a picture and reason is: Warning: move_uploaded_file…failed to open stream: Permission denied in … under windowsXP.
    I did following step:
    1.check php.ini for safty_mode:is OFF.
    2.check IIS access setting:write permission
    3.check FTP access setting:write permission
    but property of the folder is read only, then I did following:
    >- Right click on the folder where you want give write access
    >- Properties
    >- Go to the Security tab
    >- Select the Internet Guest Account ([username]/IUSR_[username])
    >- Allow the Write and Modify access. (You can give full permission)
    >- Then press Ok.
    but I found write access has been checked to defaultly deny and unchangable at deny side. And even if I uncheck read only property for the folder manually, but when I show property next, it is checked to read only again.
    What is wrong for my upload setting? Please help me, Thanks!!

  32. Rob Lang says:

    A great explanation there, another good tip would be to reset IIS after you’ve done this. To do that, type:

    [Windows Key] + R (or Start->Run)
    iisreset [Return]

    Give it a moment to run an there you go!

  33. osman says:

    great post man, thank you.

  34. Gibby says:

    Thanks, this solved what I was beginning to think was not possible ha.

  35. tre says:

    Thank you, really you’re a life savior :D

  36. Cristina says:

    Wow!! Short post, saved me hours of work!

Leave a Reply