Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Drupal - Bash shell script to fix Drupal 8 permissions where the PHP Handler is FastCGI.
#!/bin/bash
path=${1%/}
user=${2}
group=${2}
help="\nHelp: This script is used to fix permissions of a Drupal 8 installation in which the PHP Handler is FastCGI\nYou need to provide the following arguments:\n\t 1) Path to your drupal installation\n\t 2) Username of the user that you want to give files/directories ownership\n\nNote: This script assumes that the group is the same as the username if your PHP is compiled to run as FastCGI. If this is different you need to modify it manually by editing this script or checking out forks on GitHub.\nUsage: bash ${0##*/} drupal_path user_name\n"
echo "Refer to https://www.Drupal.org/node/244924"
if [ -z "${path}" ] || [ ! -d "${path}/sites" ] || [ ! -f "${path}/core/core.api.php" ]; then
echo "Please provide a valid drupal path"
echo -e $help
exit
fi
if [ -z "${user}" ] || [ "`id -un ${user} 2> /dev/null`" != "${user}" ]; then
echo "Please provide a valid user"
echo -e $help
exit
fi
cd $path;
echo -e "Changing ownership of all contents of "${path}" :\n user => "${user}" \t group => "${group}"\n"
chown -R ${user}:${group} .
echo "Changing permissions of all directories inside "${path}" to "755"..."
find . -type d -exec chmod u=rwx,go=rx {} \;
echo -e "Changing permissions of all files inside "${path}" to "644"...n"
find . -type f -exec chmod u=rw,go=r {} \;
cd sites ;
echo "Changing permissions of "files" directories in "${path}/sites" to "775"..."
find . -type d -name files -exec chmod ug=rwx,o=rx '{}' \;
echo "Changing permissions of all files inside all "files" directories in "${path}/sites" to "664"..."
find . -name files -type d -exec find '{}' -type f \; | while read FILE; do chmod ug=rw,o=r "$FILE"; done
echo "Changing permissions of all directories inside all "files" directories in "${path}/sites" to "775"..."
find . -name files -type d -exec find '{}' -type d \; | while read DIR; do chmod ug=rwx,o=rx "$DIR"; done
@GreenSkunk

This comment has been minimized.

Copy link
Owner Author

@GreenSkunk GreenSkunk commented Nov 3, 2016

New lines "\n" and tabs "\t" in the original script had the \ stripped away. Had to also add \ before ;
It now works for me!

@nowheel

This comment has been minimized.

Copy link

@nowheel nowheel commented Dec 2, 2017

little error in line 29.
from
echo -e "Changing permissions of all files inside "${path}" to "644"...n"
to
echo -e "Changing permissions of all files inside "${path}" to "644"..."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment