I have been receiving the same error "failed to open stream. permission denied"when trying to write a file on the server using PHP.
I tried everything on the internet to fix the error. I changed ownership of the files,directories and sub-directories on the server to "apache", I did a chmod 777
on all the files, directories, sub-directories, I ran restorecon -R
, I ran chcon unconfined_u:object_r:httpd_user_content_t:s0
on all the files, but the only thing that seemed to work is turning SELinux off completely.
I finally resolved the issue. The problem lay in the boolean parameters used by SELinux.
I performed the following command to get a list of all the booleans related to httpd.
$ getsebool -a | grep httpd
This gave a list of about 36 parameters.
I painfully went and turned on every boolean using the setsebool command until the "failed to open stream. permission denied" error went away.
When I turned "on" the httpd_unified boolean, the error went away!!
When I turned it "off", the error came back!!