Thursday, August 23, 2007

What are File Permissions

It is quite difficult to know absolutely everything located in our HelpCenter, which even in the case where a person does have great knowledge about web hosting and our support features, he or she may still have questions regarding their web site and hosting account. This is one reason why we offer 24/7 support and are always available via email to help you with your hosting needs. Here we will talk all about file permissions.
All files that you upload to the server have specific file permissions set. These permissions decide if a file can be: executed (in case it has scripting), read, or written to and modified. File permissions work differently on different servers. On unix based servers, you have read, write, and execute. Below, you will find a breakdown of these permissions and what they mean.

First, we will break down the three parts of a files permissions. We have the owner permissions, the group permissions, and the world permissions. The owner permissions decide what a user can do when logged in with their username. The group permissions decide what members of a group can do regardless of username. The world permissions decide what people on the internet can do with a file.

If this sounds confusing, look at the example file permissions below for a file called index.php:

-rwxr-xr-x username grpname index.php

* The - represents the placeholder for file type.
* The blue rwx are the permissions for the owner that logged in.
* The green r-x are the permissions for the group the user belongs to.
* The purple r-x are the permissions for the world, which are people on the internet accessing the file.


The values for the letters and dashes are below:

* A - is a value of 0.
* An r is a value of 4 and means READ access is allowed. This means that the file can be read.
* A w is a value of 2 and means WRITE access is allowed. This means that the file can be written to and modified.
* An x is a value of 1 and means EXECUTE access is allowed. This means that the file can be executed (only if it is a script).


When we examine the permissions for the index.php file, we find the following:

1) We are dealing with a file. The first - is left a dash to indicate that this is a file we are dealing with. If this were a directory, instead of a -, you would see a d.

2) The rwx means that the user for this file (the owner) can read, write, and execute the file. When you add the values together, r (4), w(2), and x(1), you get 7. So the permission for the owner of the file is 7.

3) The r-x for group means that any member of the group associated with this file can read and execute the file but they cannot write to it or modify it. When you add the values of r(4), -(0), and x(1), you get 5. So the permission for the group of the file is 5.

4) The r-x for world means that people visiting the site and accessing the file may read the file and execute it, but cannot write to it or modify it. When you add the values of r(4), -(0), and x(1), you get 5. So the permission for the world of the file is 5.

You put the 7, the 5, and 5 together and say that the permissions for index.php are 755. A 755 permissions for a file such as INDEX.PHP is required if you intend to run the PHP code and have it output HTML.



IMPORTANT NOTE: NEVER SET A FILE OR FOLDER TO 777 unless you know why you are doing it. GIVING 7 to WORLD will allow visitors to write, modify, or remove your files.

No comments: