Web Servers and File Permissions

In order to create webpages using your MCECS account, it is important to know how web servers and file permissions work in a Linux environment. This guide is intended for novice Linux users and gives a brief overview of:

 

How Web Servers Work

A web server transmits files from a hosted directory to a web browser via HTTP requests. The contents of the transmitted files are then displayed in the web browser. The current web servers used by MCECS run Apache 2.4.

A requested file must have appropriate permissions assigned to it that allow access by the web server. File permissions determine who can read, write, and execute a given file. The web infrastructure in MCECS is Linux-based, which means that the permissions of files in hosted directories must be changed by using the Linux command chmod.

From a Linux terminal, you can view the permissions of the contents in the current directory by running the “ls -al” command. The following image is the result of running this command in the directory /home/username/web, where your public_html and dev_html directories are located:

 

File Permissions in Linux

As is mentioned above, in order for a web server to transmit a file to a web browser, the requested file has to have the correct permissions. There are three permission sets that control who can read, write, and execute a given file. In order from left to right, these permission sets are:

  1. The owner of the file (i.e. the user).
  2. Members of the user’s group (in this case, fellow MCECS users).
  3. Everyone else outside of the internal MCECS network.

Each set has three permission types represented by a letter. In order from left to right, they are:

  1. Read – “r”
  2. Write – “w”
  3. Execute – “x”

If a given permission type is represented by one of three letters above, that particular permission type for that set is granted. If a given permission type is represented by a “-” instead, that particular permission type for that set is not granted.

 

You can change permissions of a target file or directory using the chmod Linux command.

 

Changing Permissions Using chmod

There are numerous ways to change permissions using chmod, but we will focus on using the octal-mode syntax in this guide. This syntax assigns a numerical value to each permission type:

  • Read = 4
  • Write = 2
  • Execute = 1

To indicate which permissions in a set to enable, we would add the numerical value of the enabled permissions together.

For example, suppose we wanted to enable read and execute permissions for the “user” and “group” permission sets, and no access for the “others” permission set of a given file. The numerical value of enabling read and execute is given by:

Read + Execute = 4 + 1 = 5

To allow read and execute to the user and the user’s group, and no permissions to others, we would run the chmod command from a Linux terminal as follows:

chmod 550 <file or directory name>

You can find more information about how to use chmod by reading its man page with the following command:

man chmod

With a basic understanding of file permissions and changing them in a Linux environment, you can now make files accessible from a web browser.

 

Web Browser Navigation

Suppose you navigated to your public_html directory from a web browser using the following URL:

https://web.cecs.pdx.edu/~username

In response to this request, the web server will attempt to transmit to the web browser all of the contents of your public_html directory located at:

/home/username/web/public_html

This means that navigating to files in public_html from a web browser works in exactly the same way as navigating to them from a terminal via file paths. For example, suppose you create a new directory in your public_html directory called “testdir” and within this new directory you create a text file called “test.html”. The full file path of “test.html” would then be:

/home/username/web/public_html/testdir/test.html

Similarly, to view “test.html” in a web browser, you would navigate to:

https://web.cecs.pdx.edu/~username/testdir/test.html

Navigating throughout the contents of your dev_html directory from a web browser works in exactly the same way.