Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.



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.

share|improve this question
Should accept Ignacio's answer. – Mike Purcell Jan 26 '12 at 7:50
done :) thanks! – yati sagade Jan 27 '12 at 14:51
up vote 2 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.

share|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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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