You got an account on a server for a class. You created a public_html directory, and set the permissions on it. What do you do if it does not work?

Get more information

Check the console for problems
For example, under Firefox, select these from the drop-down menu:
Tools - Web Developer - Web Console
You will see some diagnostic stuff on the page, either under the page content, or possibly to the side. Make sure it is on the "console" (between Inspector and Debugger).
Firefox browser window, with the consolue utility shown at the bottom of the window.
This should give you usedul information, and often indicates which line in what file has the problem. You might have a simple html page all in one file, or you might have a page that calls in many resources, such as javascript pages. This should help you track down which line in which file is causing the error.

403 Forbidden Access

On one server, an assignment says to set up a public_html directory, and copy an image ("Pounce.png") to it. This is easy enough, except that we got a 403 "Forbidden" error for "Pounce.png" when trying to show it in a webpage.

First, check the permissions to make sure the world can read it. In this case, we can see another graphics file in that directory. The permissions are 644 (read/write for owner, read for group, read for world), which looks fine. The permissions for the public_html directory are fine, too: r-x for world. In fact, the permissions appear to be the same for both PNG files. So why can we see one but are forbidden access to the other?

The machine runs CentOS, which supports extended permissions. This is relevant because another server I am work with (running MacOS) does not, and the commands below do not work on it. It also did not give me this problem.

[public_html]$ ls -lZ [Pp]ounce*
-rw-r--r--. username username unconfined_u:object_r:httpd_user_content_t:s0 Pounce2.png
-rw-r--r--. username username unconfined_u:object_r:user_home_t:s0 Pounce.png

See how "Pounce.png" has the attribute "user_home_t" instead of "httpd_user_content_t"? That's the problem. Even though the file is under the public_html directory, and the rwx permissions are correct, the server is blocking access to the file.

The users can run "chcon" to fix this, or the systems administrator can run it. This appears to fix the problem:

[username]$ chcon -R -t httpd_sys_content_t public_html

By the way, don't run commands like this unless you understand what they do. From the "man" page on chcon, it will "change file security context", with -R for recursive, and -t for type, followed by the type argument (httpd_sys_content_t). The last thing is the file to apply it.
Here's a good website for explaining what is going on here: www.petefreitag.com/item/793.cfm




-Michael Weeks, January 2021