Sales:  800-573-7846 or Live Chat

The ServInt Source

The Tech Bench: A Script for Fixing File Permissions

suPHP and FastCGI require files and folders to have a specific set of permissions/ownership different from other handlers. Without these permissions set correctly you will see a lot of errors such as: “403 Forbidden”, “500 Internal Server Error”, or simply generic errors that commonly have the word ‘permission’ in them.

It can be very time consuming to track down and check file permissions across a whole server. Luckily, fixing permissions and ownership on a server running  cPanel can be scripted. One of the members of our MST, Colin Roche-Dutch, created a simple script for ServInt called ‘fixperms’ that you can wget to any cPanel server. Simply run the fixperms script, specifying the user (or all users), and the errors disappear.  It is a good generic fix if you cannot find your permission problem, or if you have just switched your handler and need a quick way to change every user account on the server.

***WARNING!!!***
The following script is intended for suPHP or FastCGI ONLY! If you are not running either of these 2 handlers, do not run fixperms. The script will cause problems if you are running another handler such as DSO.
 
Furthermore, it is highly recommended that you run a full backup of your server before running fixperms or any other script that makes changes to multiple files.
 

The fixperms script is intended for cPanel servers only. It is dependent on cPanel’s internal scripts and file structure. If you’re on anything else (such as Plesk), it will simply fail to run. It won’t be able to do anything.

Steps to run fixperms on your VPS

1 wget fixperms and run for a single user

To use the fixperms script, simply log into your server as root, wget the file from our server, then run it. Type in the cPanel username and it will run only for that particular account.

It does not matter which directory you are in when you run fixperms. You can be in the user’s home directory, the server root, etc. The script will not affect anything outside of the particular user’s folder.

     wget http://img.servint.net/fixperms.sh.gz
     gunzip fixperms.sh.gz
     sh fixperms.sh -a USER-NAME

 

2 Running fixperms for all of the users

If you would like to fix the permissions for every user on your cPanel server, simply use the ‘–all’ option:

     sh fixperms.sh --all

 

3 Verbosity of fixperms

By default, the script runs in a ‘quiet’ mode with minimal display. However, if you’re like me, you may want to see everything that is happening. You can turn on verbosity using the ‘-v’ flag and have the script print to the screen everything that is being changed.

This is extremely useful when fixing large accounts that have many files. You can watch the changes as a sort of ‘progress bar’ of completion. The ‘-v’ flag can be used per account or with all accounts.

For one single account:

     sh fixperms.sh -v -a USER-NAME

For all accounts:

     sh fixperms.sh -v --all

 

4 The code itself, what’s in it?

If you’re curious about just how fixperms works and want to poke around under the hood before uploading, you can take a look at the code here.

Finally, as you’ve no doubt noted from the directions above, fixperms is a script run from the command line. If you’re a ServInt customer and think you’d benefit from this script but are unfamiliar with command line server administration, just open up a ticket and we’ll be happy to help.



The Tech Bench is an ongoing blog series featuring the answers to common questions the ServInt MST fields everyday. You can also find more great tech tips in the ServInt KnowledgeBase.

About Jacob Tirey

Jacob Tirey is an IT professional and former member of ServInt's Managed Services team.


The ServInt Source | Web Hosting Blog