Set an environment variable

If you like my WordPress work, check out my new plugin, Bylines. Thanks!

Just like PHP supports variables, your shell session supports environment variables that are passed through to the processes being run. WP-CLI uses different environment variables to customize its configuration. You can set them on demand, or for every session.

On demand

To set an environment variable on demand, simply place the environment variable definition before the WP-CLI command you mean to run.

# Use vim to edit a post
$ EDITOR=vim wp post edit 1
# Use nano to edit a post
$ EDITOR=nano wp post edit 1
# Use MAMP PHP executable to run WP-CLI
$ WP_CLI_PHP=/Applications/MAMP/bin/php/php5.6.10/bin/php wp

Every session

To set the same environment variable value for every shell session, you’ll need to include the environment variable definition in your ~/.bashrc or ~/.zshrc file:

# Always use vim to edit a post
export EDITOR=vim
# Always use the MAMP PHP executable to run WP-CLI
export WP_CLI_PHP=/Applications/MAMP/bin/php/php5.6.10/bin/php wp