Skip to content
Home » Web » PHP » How to Resolve Error "Failed to open stream: Permission denied"

How to Resolve Error "Failed to open stream: Permission denied"

I saw the error on PHP web page, but it's actually from Apache httpd server.

Failed to open stream: Permission denied

After searching for solutions on internet, I found it all about SELinux, so I took the actions below:

1. Change the owner to apache on target directory. Sometimes, this step is optional.

[root@test ~]# chown -R apache:apache /var/www/html/web1/uploads/

2. Add read-write privilege on this directory.

[root@test ~]# chcon -t httpd_sys_rw_content_t /var/www/html/web1/uploads/ -R

3. Let's see the security context of directories and files.

[root@test ~]# ls -Z /var/www/html/web1/
...
drwxr-xr-x. root   root   unconfined_u:object_r:httpd_sys_content_t:s0 css
drwxr-xr-x. apache apache unconfined_u:object_r:httpd_sys_rw_content_t:s0 uploads
...

The problem was solved.

Leave a Reply

Your email address will not be published. Required fields are marked *