I'm learning php, and am having a problem while writing a file upload page. In the docroot, I have index.php (the page that calls fopen) and a directory called "images", where I wish the temporary file be moved. However, fopen fails with 'permission denied' ( vide /var/log/httpd/error_log ). fopen is called requesting a write.

I scoured the net and found the problem was with permissions on the images dir. I first changed the group owner of the dir to a group different than root and added 'apache' to that group. group has w permission on the dir. (I found out that my Apache was running as user apache with

# ps aux| grep httpd

This failed.(should have worked, no?)

Again, I chowned the entire images/ dir to be owned by 'apache'. in vain.

And yes, I restarted the server after each of the above changes was made.

thanks,

Yati

PS: My reputation here doesn't allow me to self-answer within 8 hrs, so decided to edit here. With help from Ignacio, the command for changing the SELinux context of the images dir is:

# chcon -R -h -t httpd_sys_rw_content_t ./images

from within the docRoot.

thanks again.

link|improve this question
Should accept Ignacio's answer. – Mike Purcell Jan 26 at 7:50
done :) thanks! – yati sagade Jan 27 at 14:51
feedback

1 Answer

up vote 1 down vote accepted

SELinux is preventing HTTPd from writing into that directory. Use chcon to change the file context of images/ to httpd_sys_rw_content_t, and if that lets it work then use semanage to make it permanent.

link|improve this answer
Hi. Thanks a lot, but httpd_sys_rw_content_t is reported as an invalid context by chcon. – yati sagade Jul 4 '11 at 20:29
Which distro are you running? – Ignacio Vazquez-Abrams Jul 4 '11 at 20:31
fedora 15. any hints? – yati sagade Jul 4 '11 at 20:32
That's the correct value for F15. Verify your spelling, and make sure all selinux-* packages are up to date. – Ignacio Vazquez-Abrams Jul 4 '11 at 20:36
Thanks Ignacio for pointing me in the right direction. It seems the chcon command will be: # chcon -R -h -t httpd_sys_rw_content_t images Thank you – yati sagade Jul 4 '11 at 20:49
show 3 more comments
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.