owstopit Posted September 21, 2008 Share Posted September 21, 2008 Hello! First of all I apologize if this has already been answered and I have looked. I am very new to php and while I don't have much trouble with writing php, I am very unfamiliar with servers and how they work. I just started learning php and I've been working out of the friends of ed book PHP Solutions. I have been using Apache on Mac OSX as a test server. Right now I'm working with a simple piece of php that basically just takes what is written into a text field and writes it to a txt file using the fopen_write function. Whenever I run the script I get the [function.fopen]: failed to open stream: Permission denied error. I have read that folder permissions and file permissions can be the cause of this. I tried changing the permissions to read + write for both the file and folder but still nothing. I also read on the php website that sometimes this happens because you need to change the system account in Apache. I do not know how to change the system account, nor do I know how to fix this problem! Please help! Thanks so much for your time. -Neal Quote Link to comment Share on other sites More sharing options...
shortj75 Posted September 21, 2008 Share Posted September 21, 2008 try this $filename="$_POST[title]"; if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } if (fwrite($handle, $body) === FALSE) { echo "Cannot write to file ($filename)"; exit; } that is what i use well close to it i change it a little the file name is the full path on my server like C:/drive/location i hope this helps fclose($handle); Quote Link to comment Share on other sites More sharing options...
chronister Posted September 21, 2008 Share Posted September 21, 2008 try chmodding to 755 or 777. If you chmod to 777 and you still cannot write to the file, then you may need ot change the user that apache runs as. Not sure how to do that though. Quote Link to comment Share on other sites More sharing options...
owstopit Posted September 21, 2008 Author Share Posted September 21, 2008 Ok, I am not sure how to chmod, but I'd like to try it! Can you tell me how to do it? Quote Link to comment Share on other sites More sharing options...
chronister Posted September 21, 2008 Share Posted September 21, 2008 chmod is the file permissions. grab your favorite ftp client and connect to your server. I use coreFTP free edition. Go to the file and right click. choose properties and then set them for user group world read read read write execute execute execute This is 755 Read is worth 1, write is worth 2 and execute is worth 4, so user 4+2+1=7, group 4+1=5 , world 4+1=5 Nate Quote Link to comment Share on other sites More sharing options...
owstopit Posted September 21, 2008 Author Share Posted September 21, 2008 Ok, the only problem now is that I'm not doing this on my domain server, I'm just doing it on my local server. How do I connect to my local server (the one setup by apache) in an ftp program? I tried just entering the ip address but that doesn't seem to work. As you can see I am pretty n00bular when it comes to this kind of stuff but even knowing that I can set that file permission with an ftp client is helpful to me! So, how can I connect to my local server through an ftp client? Quote Link to comment Share on other sites More sharing options...
chronister Posted September 21, 2008 Share Posted September 21, 2008 I forgot about the whole local server thing. I am not sure how to set permissions on mac os. I assume if you set them for read/write permissions it should work for ya. Thats all I got. Nate Quote Link to comment Share on other sites More sharing options...
owstopit Posted September 21, 2008 Author Share Posted September 21, 2008 Hm, well I went to the folder properties and set them to read and write for my account (the main account on Mac OSX) but there are many possible accounts to grant permission to. Maybe I'm granting permissions to the wrong one? I don't have time to right at this moment, but I will post the code, as perhaps there is a problem with my script? Until then, does anyone know what account I need to grant permission to? Here are some of the possible accounts I can grant permission to: -accessibility -admin -amavisd -appowner and many more in alphabetical order. Hmm, just not sure what to do here, I'll post the code later today. Thanks for the help so far, I'm sure we can figure this out! thanks -Neal Quote Link to comment Share on other sites More sharing options...
chronister Posted September 21, 2008 Share Posted September 21, 2008 I'm sure mac has a method of determining which account your webserver is running under. I would think that if you can determine this and then give that user the permission, you should be good to go. Nate Quote Link to comment Share on other sites More sharing options...
owstopit Posted September 22, 2008 Author Share Posted September 22, 2008 Well, I fixed it! Turns out Apache is running under user "www". What confused me is that I had already given the folder permission for "other" which includes all of the accounts, but hadn't actually applied it to the folder! So, don't make the same mistake I did: if you're changing folder permissions in OSX always press "apply to enclosed items" when you're done! I fixed it by applying permission to every account, then decided I wanted to know which one it was specifically and after trying a few that seemed likely it turned out that 'www' was the right account. So I guess it's useful to know that for users of OS X 10.4.11 (tiger), apache may very well use account 'www'. Thanks so much for the help everyone! -Neal Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.