GIST: Set Drupal File Permissions

Save this file as a Bash script (.sh) and make it executable, this will set the appropriate file mode for your Drupal website. Make sure to customize the script for your environment.


echo "Type the directory from ~/Documents/sites/, followed by [ENTER]:"

read dir

cd ~/Documents/sites/$dir

echo "Updating owners..."

chown -R <user_name>:_www .

find . -type d -exec chmod u=rwx,g=rx,o= {} \;
find . -type f -exec chmod u=rw,g=r,o= {} \;

cd sites
echo "Changed to:"

find . -type d -name files -exec chmod ug=rwx,o= '{}' \;
find . -name files -type d -exec find '{}' -type f \; | while read FILE; do chmod ug=rw,o= "$FILE"; done
find . -name files -type d -exec find '{}' -type d \; | while read DIR; do chmod ug=rwx,o= "$DIR"; done

echo "Permissions Updated!"