file_put_contents Linux permissions question

I'm finally starting to deploy my site and code on a Linux box. Everything to this point has run on Windows.

Anyway, I'm running into a problem with a plug-in that uses file_put_contents(). It keeps failing. I know the path is correct because I have a previous check confirming that the directory is correct. So, I'm assuming the problem is permissions.

So what's the proper deal with setting up permissions for directories and files in Linux, so a PHP script running in Apache (with whatever group and user is normally assigned to Apache) can successfully write a text file? I know I could, theoretically, slam 777 on all the directories, but that seems to lack finess (and security).

Also, what's the permissions difference if I want to write to a directory under htdocs vs. one located outside the htdocs tree? And should I be doing anything special with directory group as well?

Basically, the entire write is failing, and I haven't been able to make it succeed. Advise welcome.

Thanks!

PS: Back in the UNIX days, when men were men and computers were made from wood, I knew all this stuff like the back of my hand. But times, they have changed.