Saturday, August 4, 2012

Setting Permission for PHP/IIS Environment Especially When PHP Temporary File Facility Is Used

When PHP is run on IIS platform, users will run into the following problems:
  • (A) Files are not able to be written, created, or rewritten on the C:\inetpub\wwwroot\ directory.
  • (B) PHP uploaded temporary file will not be able to be written and this results in file upload problem. For example, $_FILES["FileID"]["tmp_name"] will not be able to be written.
  • (C) PHP tmpfile() command will fail.
In order to solve this problem, permission on the windows directory should be set correctly. For Linux, it's simple. For windows, it's a bit tricky. You can set the permission on IIS/Windows system using these steps:



  1. Go the folder you want the permission changed to IIS/PHP friendly settings. Right click on the folder and select Properties.



  2. Select the Security Tab.



  3. Click on Edit as indicated above. (There's no need to select Group or User at this point)



  4. Refer to the screen capture above, select Users(YourComputerName\Users). Then check the Full Control Allow and then click on Apply.
  5. Repeat Step D above but this time, select IIS_IUSRS(YourComputerName\IIS_IUSRS) (4). Then as in step D, check the Allow for Full Control (2) then Apply (3). Press OK and then OK again.
You now have set a loose permission for IIS/PHP to perform file operations on the folder you just fine-tuned above. My recommendation for the permission settings may be too loose for some. It's more meant for the PC or notebook in which you are only one who can access to the files. Now in order to solve (A)&(B) problem above, you just need to select the target folder to be granted full permission and repeat the steps above. In order to solve problem (C) above (tmpfile() not working), you need you loosen the C:\WINDOWS\Temp permission. As for problem (B), you also need to check out the phpinfo() by adjusting the PHP.ini so that you see where your temporary is:



You can use the search of 'tmp' and you'll find it in the first search result. Then set the php.ini according to your need. You can also set it to C:\WINDOWS\Temp but you need to grant the permission for PHP to store the temporary file here.

No comments:

Post a Comment