PHPMatters Help You Better Hosting Your PHP-based Sites
How to Change File Permissions to Increase the Level of Website Security

How to Change File Permissions to Increase the Level of Website Security

When managing a website, the file permission is pretty essential as it decides who can access, read, write, and modify your files. It is unavoidable that you may have some valuable files that cannot be touched by anyone else except you, otherwise you may encounter the security issues. In this case, we’d like to tell you how to change file permissions to protect you away from potential dangers and vulnerabilities.

Basic Knowledge of File Permission

There are three actions for files including Read, Write, and Execute that can be replaced with the number of 4, 2, and 1 respectively. According to the action name, you can figure out simply that

  • Read 4 allows people to read and view the files.
  • Write 2 allows people to edit the files for some changes and modifications.
  • Execute 1 allows all the actions on the files including read, modify, remove, and many more.

In addition to the file actions, you also need to know the targeted permission groups. In fact, there are only three groups to whom you can change the file permissions, including User, Group, and World.

  • User means you – the owner of the files and the website.
  • Group means other people residing in the same web server as you.
  • World indicates everyone on the Internet that access your website and files.

permission modesTo make the permission changing an easy task, all the file actions are showed as three numbers. Sometimes you may find that the permission mode has four digits with the zero placed in the first place. Simply ignore the first one as zero means no permission that is nonsense in this case.

Generally, the three numbers can be combined in many ways for different permissions, but we suggest you to have the permissions of 644 or 755 for both of your files and folders.

  • 644 allows you to read and write the file, and allows others to read only.
  • 755 allows you to do anything you want with the file, and others to read and execute the file.

For the common files and folders, it doesn’t matter when you allow the executable permission. In terms of the some sensitive ones, however, the permission of 744 is better. Note that 777 OR 0777 is not recommended.

Special Note

The reason why you change the file permissions is to reduce the possibility of hackers to modify the files on your website. It is useful in the most cases, but it may also cause problems in some special occasions. For instance, if you want to install a PHP based script to your website, the script needs to have the permission to edit some of your files. As PHP generally is treated as a strange visitor on the server, it cannot modify your files if you set the last 2 numbers as 2, 1, or 3.

In fact, if your web server has the suPHP integrated, then the issue can be resolved easily as suPHP can run PHP as the file owner.

How to Change File Permission

After getting the basic knowledge, the changing process can be easy. Here, we highly recommend you to use the File Manger that can be found from almost all the popular control panels. Generally, you can get to this tool under the File tab.

file manager

Then, you can see a long list of files included within your website. You simply need to right click the one that you want to change the permission, and then choose the Change Permissions button. Note that you can check the file permissions of your files from the last Perms column by figuring out the numbers we have introduced previously.

file permission button

Now, you can see a small window appeared allowing you to set the permissions easily. You only need to check the right boxes based on the actions and targets. The corresponding number can be figured out clearly. Then, don’t forget to click the Change Permissions button.

change permission

In addition to the File Manager, you can also make use your FTP. After connecting to your FTP server, you only need to focus on your targeting file and right click it to choose the Properties. Then, things can be the same as the former method. You simply need to change the values by clicking the boxes, and then click the OK button.