Last active
March 28, 2017 14:27
-
-
Save ssaki/c2e75849821c12f5319522d5743ddfa1 to your computer and use it in GitHub Desktop.
CLI script to setup Symfony's cache/log directory permissions (supports both 2.7- and 2.8/3.0+)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Based on instructions from Symfony's documentation (setfacl section) without any modifications: | |
# http://symfony.com/doc/current/setup/file_permissions.html | |
# | |
# Usage: | |
# 1. Copy to /usr/local/bin (or any other directoy in your path) | |
# 2. make the script executable: chmod +x /usr/local/bin/fix-sf-permissions.sh | |
# 3. Invoke from within a directory hosting a symfony project (top level only) | |
CWD=`pwd` | |
if [ ! -d "$CWD/var" ] && [ ! -d "$CWD/app/cache" ] && [ ! -d "$CWD/app/logs"] ; then | |
echo -e "Current directory does not look like a Symfony2/3 project\n\n" | |
exit 255 | |
fi | |
HTTPDUSER=`ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1` | |
if [ -d "$CWD/var" ]; then | |
echo -e "Setting up permissions for var/ (Symfony 3 style) ..." | |
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX var | |
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX var | |
else | |
echo -e "Setting up permissions for app/cache and app/logs (Symfony 2 style) ..." | |
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs | |
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs | |
fi | |
echo -e "\nDone!\n\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment