1

I can't fopen a file for writing unless I enable "execute" permission for the directory that it's being created in. That seems strange. Why is "write" permission not enough?

It's a very simple fopen, fputcsv loop, fclose sequence. Nothing else is being done with files in that directory.

Basic config - Centos, Apache, PHP

Thanks

Cyrcle
  • 1,363
  • 3
  • 13
  • 25
  • 4
    This might have to do with SELinux (http://en.wikipedia.org/wiki/Security-Enhanced_Linux) since you are using CentOS. – summea Feb 04 '12 at 18:23

2 Answers2

2

"On a directory, the execute permission (also called the "search bit") allows you to access files in the directory and enter it, with the cd command, for example." source -- good discussion of file permissions

gcbenison
  • 11,723
  • 4
  • 44
  • 82
1

This might have to do with SELinux. Basically, SELinux gives you more control over what processes and daemons can do... a sort of boundary system that goes beyond the normal user/group permissions. It can be helpful for fine-grained control, but it can get in the way, sometimes.

There are ways to turn it off (see http://linuxconfig.org/how-to-disable-selinux).

But, there are also ways to fine-tune the settings (see: http://sheltren.com/stop-disabling-selinux) which might be better in the long run. You could also try a different distro if you aren't tied to CentOS.

EDIT:

Also, if this doesn't have to do with SELinux, as sepp2k mentioned in the comments below, you may want to take a look at the section titled "Execute Permission" on this file and directory reference guide by Wayne Pollock.

Community
  • 1
  • 1
summea
  • 7,390
  • 4
  • 32
  • 48
  • 2
    This has nothing to do with SELinux. You can't create, modify or read files in a directory that you don't have execute permissions on. That's normal behavior. – sepp2k Feb 04 '12 at 20:15
  • Something like this type of question has been asked recently here on SO... (http://stackoverflow.com/questions/8998743/rhel-php-writing-files-outside-var-www-html/8998776) and (http://stackoverflow.com/questions/9056628/php-cant-write-outside-of-the-document-root-no-matter-what/9059696) Maybe I'm wrong. Doesn't hurt to post your own answer, as well. – summea Feb 04 '12 at 20:44
  • You do bring up a good point about `execute` permissions, though: http://content.hccfl.edu/pollock/AUnix1/FilePermissions.htm (Execute Permission section) Edited my answer to reflect that possibility. – summea Feb 04 '12 at 21:17