Author |
|
roger
Joined: 08 May 2009 Posts: 5 Location: Canada
|
Posted: Fri 08 May '09 20:20 Post subject: windows 2008 file permissions and php/apache |
|
|
Hello, I did search thru this forum and did not find an answer. maybe I missed it.
I installed Apache 2.2/PHP5 on Windows 2008. By default php has write access to all folders/files. How do I fix this?
ntfs permissions for Users on the folder I want to have read only has write unchecked. There is only System and Administrator with full permissions. I am obviously missing something??
Thank you |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Sat 09 May '09 0:21 Post subject: |
|
|
Windows services by default run as System, therefore have read/write thoughout.
You would need to create a user (say "apache" like on most *nix machines). In the properties for the service, change it to log on as that user. Now it's under everyone, till you start adding apache to the folder permissions and start removing write.
http://www.justmyspace.org/apwinperm.html
This is an example done on XP .. you should be able to do same on 2008, probably a little differently. I do not remember if I tried it on the Win 2008 Server RC that I had tested before it's release. |
|
Back to top |
|
roger
Joined: 08 May 2009 Posts: 5 Location: Canada
|
Posted: Mon 11 May '09 4:39 Post subject: |
|
|
thank you for the response. I now have all www folders files using only the following services Apache, Admin and Local System. I have Apache service set to use Apache user and confirmed in task manager that it is using that user.
I removed write ability for Apache on a folder or file and Apache cannot write to it. Great. Here is the problem I still have to resolve. using php to upload a file... PHP thinks it uploaded a file, but no file is uploaded. Grant write access on that folder the file is uploaded (the script is working).... Or if you use a script to check if php has write access on a file, php thinks it does when it does not.
How do I have php be aware of permissions? That is, if there is no write access why does it think it has write access and how to make php know that it does not?? |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Mon 11 May '09 7:53 Post subject: |
|
|
This I'm sure is not the best solution .. I lack in php ... but have it write a temp file .. if it cannot then turn around and find/delete it ... then it didn't get written and php has no write access. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Mon 11 May '09 10:08 Post subject: |
|
|
After uploading you need to move the file from the temporary folder to the destination folder
short example
Code: |
<?php
$path_parts = pathinfo(realpath($_SERVER['PHP_SELF'])); //self config path
$uploaddir = $path_parts['dirname'] . 'upload/'; //path to tupload folder
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $_FILES['userfile']['name'])) {
?><b>Upload successful<br /><br />
File: <?php echo $_FILES['userfile']['name'] .'<br />';
}
else
{
?>Upload failed! Please try again<?php
print_r($_FILES);
}
?>
|
For more details see the manual http://de2.php.net/manual/en/features.file-upload.php |
|
Back to top |
|
roger
Joined: 08 May 2009 Posts: 5 Location: Canada
|
Posted: Mon 11 May '09 16:59 Post subject: |
|
|
thanks for the response. I should not have to do anything in php. Example: on my IIS6 server with php using the same code... when uploading a file to a folder that does not have write permission I get a permission denied error.
on apache, this does not happen, php gets no error and thinks it has done the upload. I do not think this should be the bahaviour? |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Mon 11 May '09 19:39 Post subject: |
|
|
good point .. but IIS does not run on BSD/Linux/Unix/Mac/AIX/the list is long, Apache does. I can imagine something made for only Windows by MickeyMouseSoft is going to be a little better at some things on Windows, so in a way it is unfair to expect the exact behavior.
I remember the days when all the IIS folk were cleaning/reinstalling their machines thanks to Code Red/II and us Apache folk just sat back and .. well .. laughed.
Same thing sort-of just happened end of last year/beginning of this year with MSSQL. Those folks were cleaning their databases one or more times a day .. for months.
So that exclusive interoperability has it's price as well. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Mon 11 May '09 22:29 Post subject: |
|
|
roger wrote: |
I get a permission denied error.
on apache, this does not happen, php gets no error and thinks it has done the upload. |
IMHO that is a question of code design. Of cause you can write your PHP code to check if the folder is writeable. I think any code should run on several systems. But that is just my opinion.
For me is TCO one point which software I use and apache + PHP is free.
I don't want a religios war about the right OS or better server. I try only to solve your uploading problem.
By the way did you turn on error reporting in PHP? |
|
Back to top |
|