What file permissions and ownerships are appropriate for the files directory and subdirectories? Possible Duplicate:
  What are the recommended directory permissions?  




I've scoured the net, and it seems that everyone has different methods of doing this and I just want to get a quick straight answer if possible. So i'm on Centos with apache installed. 

I know the files folder has to be 777, but 777 is insecure as anyone can write to it, but isn't that what we need since anonymous users have to write to it when they upload to the server like images or what not? And not to forget drupal throws an error if its not 777.

Also if my user for that domain is foo, then the ownership of files and all its items inside would be foo:foo  correct? But im reading it should be foo:www-data ? so which one is it?
It depends somewhat on your server configuration but it doesn't have to be 777, and in fact it should not be 777 as that is a security issue.

The web server user (on your server, not your drupal site) is what has to be able to write to the files directory. Whether the drupal user is logged in or anonymous is unrelated.

For information on this see http://drupal.org/node/244924