Skip to content

Instantly share code, notes, and snippets.

@svenvarkel
Created December 20, 2013 22:40
Show Gist options
  • Save svenvarkel/8062778 to your computer and use it in GitHub Desktop.
Save svenvarkel/8062778 to your computer and use it in GitHub Desktop.
Fix file permissions in your Magento project folder. It has some constraints: - use group name "dev" for your developers and your "php/web server user" (www-data) - it's untested in other environments than Debian/Ubuntu
#!/bin/bash
#
# This script fixes permissions on Magento subtree
#
# Usage:
# cd to virtual host folder
# run script by issuing utils/fix_permissions.sh . command
#
# Author Sven Varkel <sven@mageflow.com>
# Copyright 2013 MageFlow Ltd
project_folder=$1
if [ -z $project_folder ]; then echo "Project directory parameter not specified. Using current folder $(pwd)"; project_folder="."; fi
os="Linux"
web_user="www-data"
environment=$(uname -a)
if [[ $environment == *Darwin* ]]
then
os="OSX"
fi
if [ -e "/etc/redhat-release" ]
then
distro="redhat"
web_user="web"
else
#Assuming quite dubiously here all others are debian/ubuntu:)
distro="debian"
web_user="www-data"
fi
if [ $os == "Linux" ]
then
echo "Working in Linux"
echo "Fixing group"
sudo chown -R ${web_user}:dev $project_folder
echo "Done."
echo "Fixing permissions of directories"
find $project_folder -type d | sudo xargs -I{} chmod g+rws,o-ws "{}"
echo "Done."
echo "Fixing permissions of files"
find $project_folder -type f | sudo xargs -I{} chmod g+rw,o-w "{}"
sudo chmod a+x $project_folder/utils/*.sh
chmod +x $project_folder/public/mage
echo "Done."
fi
if [ $os == "OSX" ]
then
echo "Working in OSX"
echo "Fixing group"
sudo chgrp -R localaccounts $project_folder
echo "Done."
echo "Fixing permissions of directories"
find $project_folder -type d | sudo xargs -I{} chmod g+rws,o-ws "{}"
echo "Done."
echo "Fixing permissions of files"
find $project_folder -type f | sudo xargs -I{} chmod g+wr,o-w "{}"
sudo chmod a+x $project_folder/utils/*.sh
echo "Done."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment