Created
June 5, 2017 15:55
-
-
Save frankiejarrett/f6a1f2001e4baf7dc13c3ec10c58fb3a to your computer and use it in GitHub Desktop.
Bash alias to allow root to run WP-CLI commands as another user
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
# force `wp` commands to run as the `www-data` user | |
wp() { | |
if [ $1 == "cli" ]; then | |
command wp $* --allow-root | |
elif [ $(whoami) != "www-data" ]; then | |
su www-data -c "wp $*" | |
else | |
command wp $* | |
fi | |
} |
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
# force `wp` commands to run as the `www-data` user | |
wp () { | |
if [ $1 == "cli" ]; then | |
sudo -H -u root bash -c "wp $* --allow-root" | |
elif [ $(whoami) != "www-data" ]; then | |
sudo -H -u www-data bash -c "wp $*" | |
else | |
command wp $* | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment