Deploy

Whacking File Permissions After Deploying

Lately I’ve been fixing permission problems every time I update a working copy to the live server from a GIT repository. Permissions are set according to the settings in my Windows machine which has execute permission to all files. It should have not execute bit so I need to change them all to 0644.

Searching bits of one-liner

I remember that there was a command for Kohana to fix permissions after extracting the source code from ZIP. Visiting the site leads me to the installation page and there you go – I got the linux command on how to set permissions according to type ex: regular files or directories.

To set the directories so that they will have the conservative 0755 permission, we execute the command below on the project root:

find . -type d -exec chmod 0755 {} \;

The command above will set the 0755 permission to directories only, so that regular files can’t have execute permissions.

For regular files (does not apply if you have shell scripts), we execute the command below on the project root:

find . -type f -exec chmod 0644 {} \;

The command above sets the 0644 permission to all regular files, usually php, css, js and image files. The permission is so conservative that it only allows read write access to the owner of the file and grants read access to the rest of the world.

Finishing things up

We still need to set a appropriate ownership of the files/directories.

chown user:group -R *

Leave a reply

Your email address will not be published. Required fields are marked *