Apache returns 403 on file with correct permissions
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Apache returns 403 on file with correct permissions
Good afternoon,
This is my first post here and I want to thank you in advance for reading this and providing any advice you may have!
I have a new install and am setting up apache, mysql, and phpMyAdmin. I have changed the group for the www and all subdirectories to 'web'. I have left the permissions untouched.
Every file I take out of the phpMyAdmin archive has this same problem, so I have reduced it to one file to demonstrate.
The file is named Documentation.html, and per the instructions contained in it I have extracted the file to the document root [ /var/www/html ].
I have created a test file called test.html in the same directory which works just fine. At this point my ls -l shows:
-rw-r--r-- 1 jon23d jon23d 192655 May 12 09:31 Documentation.html
-rw-rw-r-- 1 jon23d jon23d 59 May 23 16:01 test.html
When I try to view documentation.html through apache I am returned a 403.
When I change the permissions to be the exact same as test.html I recieve the same problem. jon23d is a member of the web group which owns /var/www & /var/www/html.
Next I copied Documentation.html to test2.html. I changed no permissions at all. Apache allows me to view this file just fine.... Help!
The problem isn't the permissions, but the file's SELinux context. You probably moved Documentation.html into the /var/www/html directory, maintaining its (incorrect) context. When you copied the file, the newly created file inherited the (correct) directory context.
You can see this with 'ls -Z' on the files in question. What you probably need to do is:
While what I read was still rather confusing - it did fix the problem. I believe that I understand now that this is a second layer of security enabled system-wide on a per-program basis. Are you aware of a way to ensure that the correct context is set automatically when I unzip a file in the future?
If you create a file in a directory, it will inherit that directories context. So if you unzip a file in /var/www/html, it has the appropriate permissions for a file served by apache. For example, if you have a new version of Document.html in /home/someuser/document.zip, then:
cd /var/www/html
unzip /home/someuser/document.zip
This will create the file in the directory, and it will have the correct context. Alternatively, you can just set the context manually with chcon.
After a little experimenting I discovered that unzipping directly into the directory will only work if I first copy the file from the CD to that folder. I cannot extract directly from the disk or from another folder. Thanks again!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.