Drupal: Set file permission on filesystem with a shell script

This script is to set all file permissions at once for a Drupal website.

!/bin/bash
# Script made by David Rush, davidprush@gmail.com
# Changes the permissions of the Drupal sites directory to secure after isntallation
# Very Important Put this script in the same directory as your site/ directory
# You are free to distribute, change, delete, or whatever the hell you want with this script

echo "Start fixing permissions..."

# Declare some DIR paths
FILES="sites/default/files"
SETTINGS="sites/default/settings.php"
SITES="sites"
DEFAULT="sites/default"
THEMES="sites/all/themes"
MODULES="sites/all/modules"
DSETTINGS="sites/default/default.settings.php"

# Paths for binary files
TAR="/bin/tar"
RM="/bin/rm"
CHOWN="/bin/chown"
FIND="/bin/find"
CHMOD="/bin/chmod"

# Change permissions to be secure

$CHOWN -R www-data:www-data sites

$CHMOD 775 ${SITES}

$CHMOD 775 ${FILES}

$CHMOD g+w -R ${FILES}

$CHMOD 440 ${SETTINGS}

$CHMOD 440 ${DSETTINGS}

$CHMOD 755 ${DEFAULT}

$CHMOD 755 -R ${THEMES}

$CHMOD 755 -R ${MODULES}

echo "Done fixing permissions, verify all permisssions are correnct!"

# script done

For Plex installations change $CHOWN -R www-data:www-data sites to $CHOWN -R SOMETHING:apache sites

Thanks to David Prush

Post new comment
The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.