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!

  • http://www.roland.co.nr Roland

    Is theres a way to set this permission through FTP?

  • http://www.eKhoury.com fusion

    Well I’m not sure you can do that…

  • masima

    This entry was useful very much. Thank you.

    from Japan.

  • http://www.tasolglobal.com dave

    Does Not Work

  • Tim

    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

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

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

  • http://www.flash2mobile.com sameer

    Very useful post. :)
    Thanks!!

  • nino

    Thanks alot

    I am really happy to find the answer..

    once again thank you so much

  • prabha

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

  • Feijão

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

  • http://mytrail.org wild_bill

    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!

  • par_ten

    Thank you very much.

  • par_ten Thailand

    Thank you very much

  • Jon

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

  • FetkaN

    Thanks man !!!! you rule !!

  • RedSun

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

  • Biko

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

  • Sridhar

    Thanks a lot.

  • John

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

  • metaljey

    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.

  • Ulf Lunde

    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.

  • Demola

    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

  • http://www.bluetigerIT.com Adrienne

    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.

  • Shamsul Akmal Ahmad

    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.

  • stardog

    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.

  • http://www.imeem.com/people/UrLHU6j Petillizick

    Thank you

  • Lili

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

  • http://realdreams.jiaoweijia.cn/wordpress/?p=17 file permissions —from drupal.org « realdreams my life~ my love

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

  • http://www.kale.com Kaleem

    thanks dude i like it the way ur suggestion helped.

  • http://www.gadgets.co.uk/ Gadget Man

    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.

  • estonijaan

    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?

  • Edwardo Eva

    Thank you for your help!

  • Greg

    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

  • c2ckid

    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!

  • Roger

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

  • toh.g

    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!!

  • http://www.lack-of.org Rob Lang

    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!

  • osman

    great post man, thank you.

  • Gibby

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

  • tre

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

  • Cristina

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

  • Michael

    I struggled with this for about a day and this thread lead me to a solution. Here’s my environment (two separate servers):

    Web Server
    Windows 2008R2
    IIS7

    DB Server
    RHEL 5
    MySQL 5.1.53
    PHP 5.3.3

    It did turn out to be a permission problem for me but it had to do with the default IIS7 web site connection applied to new web sites for the physical path of the web site root folder. IIS7 by default uses the Application user (pass-through authentication) to connect to the site root folder so I assumed that I just needed to give the IUSR full rights to the root but that did not work for me. Next I changed the connection to use a user that had full permissions to the root and the installation completed.

  • Yigalsh

    Thanks Michael! Giving IUSR permissions to root folder worked for me.

blog comments powered by Disqus