Skip to content

Instantly share code, notes, and snippets.

@frankiejarrett
Created June 5, 2017 15:55
Show Gist options
  • Save frankiejarrett/f6a1f2001e4baf7dc13c3ec10c58fb3a to your computer and use it in GitHub Desktop.
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
# 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
}
# 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