Last active
November 15, 2017 13:35
-
-
Save mdrmike/ebb914947a0e36aac14e1d983a8e8b76 to your computer and use it in GitHub Desktop.
set dev web permissions for wordpress site on ubuntu | wget "https://gist.github.com/mdrmike/ebb914947a0e36aac14e1d983a8e8b76/raw/1839ca600de1cd5802038aaa360f80cfe693bc9e/dev-perms-wp.sh"
This file contains hidden or 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
#!/bin/bash -ex | |
# SETUP PERMISSIONS | |
VPATH=${1%/} | |
GROUP_WEBWORK=${2} | |
WEBSERVER="www-data" | |
HELP="\nHelp: This script is used to fix permissions\nPlease provide the following arguments:\n\t 1) Path to web root\n\t 2) Shared workgroup of website. AKA group ownership\nNote: \"www-data\" (apache default) is assumed as the owner of the web files.\n\nUsage: [sudo] bash ${0##*/} [web_root_path] [group_name]\n" | |
[ -z "$VPATH" ] && VPATH=`pwd` # is null, use present dir | |
[ -z "$GROUP_WEBWORK" ] && GROUP_WEBWORK=webwork # is null, set default | |
echo -e "\n\n\nNOTICE!!!" | |
echo -e "Changing permissions of: $VPATH" | |
echo -e " and workgroup: $GROUP_WEBWORK\n" | |
echo -n "This action cannot be undone. Proceed? [y/N] " | |
read action | |
if [ -z "${action}" ] || [[ "${action}" != [yY] ]]; then | |
echo "Exiting ..." | |
echo -e $HELP | |
exit | |
else | |
echo -e "PROCEEDING ...\n\n" | |
fi | |
cd $path; | |
# SETUP APACHE AS USER:GROUP | |
chown -R www-data:"$GROUP_WEBWORK" "$VPATH" | |
# How to read command: | |
# https://en.wikipedia.org/wiki/File_system_permissions#Symbolic_notation | |
# https://en.wikipedia.org/wiki/Chmod#Octal_modes | |
find "$VPATH" -type f | xargs chmod ug=r,o= #=440 #660 adds write | |
find "$VPATH" -type d | xargs chmod ug=rX,o= #=550 #770 adds write | |
find "$VPATH/wp-content" -type f | xargs chmod ug=rw,o= #=440 #660 adds write | |
find "$VPATH/wp-content" -type d | xargs chmod ug=rwX,o= #=550 #770 adds write | |
find "$VPATH" -type d | xargs chmod g+s # setgid: new files inherit parent dir perms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment