Skip to content

Instantly share code, notes, and snippets.

@sumpygump
Created March 13, 2014 11:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sumpygump/9526413 to your computer and use it in GitHub Desktop.
Script to update the cache and logs directory with correct permissions for a Symfony project. Adapted from http://symfony.com/doc/current/book/installation.html
#!/bin/bash
# This script will update the cache and logs dirs to be owned by apache user
rm -rfv app/cache/*
rm -rfv app/logs/*
APACHEUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data' | grep -v root | head -1 | cut -d\ -f1`
echo Apache user is $APACHEUSER
chmod +a allow 2> /dev/null
if [ $? -eq 1 ]; then
# System doesn't support chmod +a
echo setfacl -R -m u:"$APACHEUSER":rwX -m u:`whoami`:rwX app/cache app/logs
setfacl -R -m u:"$APACHEUSER":rwX -m u:`whoami`:rwX app/cache app/logs
echo setfacl -dR -m u:"$APACHEUSER":rwX -m u:`whoami`:rwX app/cache app/logs
setfacl -dR -m u:"$APACHEUSER":rwX -m u:`whoami`:rwX app/cache app/logs
else
# System supports chmod +a
PERMS=delete,write,append,file_inherit,directory_inherit
echo chmod +a "$APACHEUSER allow $PERMS" app/cache app/logs
chmod +a "$APACHEUSER allow $PERMS" app/cache app/logs
echo chmod +a "`whoami` allow $PERMS" app/cache app/logs
chmod +a "`whoami` allow $PERMS" app/cache app/logs
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment