Monday, September 04, 2006

Access denied with SELinux plus apache

There were no explanation. I was going crazy. I put an image via ftp in the same directory where I put more images, but when I try to open those image I received an

access denied

So I checked once and once again the file permisssions and the rest ...

When there's no exit I use to let things rest for a few -it depends, few minutes, few days- and come back again on it later

After a search I found this note about how SELinux denies access to some application to do something on a file and how restore context to that file.

In fact, by followinf those steps I get this, first a file with their right context in SELinux policy:
[root@porta ~]$ ls -alZ /var/www/html/beta/images/random1.jpg
-rw-r--r-- pere pere user_u:object_r:httpd_sys_content_t /var/www/html/ beta/images/random1.jpg

Now a file that doesn't have their conext properly setted [root@porta ~]$ ls -alZ /var/www/html/beta/images/ayvbg45.jpg
-rw-r--r-- pere pere root:object_r:file_t /var/www/html/bet a/images/ayvbg45.jpg

And finally how to set context properly to that file (you have to be root): restorecon -v /var/www/html/beta/images/ayvbg45.jpg