Reputation: 867
I am running the standard install of PHP and Apache on OSX 10.5.8, and the CHMOD settings of the folder I am trying to open in (orders) is 777, the group is _WWW.
$filename = 'orders/54c9942b.txt';
if (!$handle = fopen($filename, 'w')) {
return(false);
}
I get the following:
Warning: fopen(orders/54c9942b.txt) [function.fopen]: failed to open stream: Permission denied in /Users/New/Sites/thisisnothere/order-save.php on line 36
*Edit: I tested it on my webserver (one I pay for, not one I set up) and it works as I expected. This leads me to believe it's an issue with configuration of my server, maybe an access issue in Apache? or PHP? I am completely unfamiliar with configuring Apache.
Upvotes: 2
Views: 4073
Reputation: 2453
I have a solution for you, but I am not a security guru, so use this solution only on your localhost and if your data is not sensitive like credit card numbers, medical information etc. Maybe some other experts here comment on that.
It makes a difference if you call php yourself directly on a console or if you call the same php file via your local web server. I found that my mac (lion) runs php via the web server as the user "localaccounts".
Then I have solved the issue as follows:
Step 1: Change the group of the current directory and the files that you need to be modified via the web server to the group called "localaccounts". E.g. Enter the following command at the terminal to apply this to the current directory, a subdirectory "user images" and the file foo.sqlite.
chgrp -R localaccounts . foo.sqlite user\ images/
Step 2: Grant the group members write permission using the commad
chmod g+w -R . foo.sqlite user\ images/
Note that the dot means current directory.
I tried the same thing on my webhoster, but they don't allow it this way. Instead they adviced me to use PHP CGI. PHP would be then executed like my FTP User access. I guess that is more secure, but I haven't tried this yet.
Upvotes: 0
Reputation: 2630
Try using the full filesystem path in your fopen() command and see if that works. Try it somewhere else you know will work, too (perhaps /tmp
).
Upvotes: 1
Reputation: 63
"If you are trying to get this program to run and you are having errors, you might want to check that you have granted your PHP file access to write information to the hard drive" taken from tizag.com So sounds like you should set the permissions on the php file itself, as Tyler stated.
Upvotes: 0
Reputation: 13131
The permission that matters is that of the file, not the directory it's in. I'm sure that's where your problem is.
Upvotes: 0