By default, using tools like wpcli with a Local site requires clicking the “Site Shell” button for any site you want to work with. This can become tedious when changing between multiple sites with the same primary terminal. Installing a third-party tool like direnv helps reduce that friction so that you can easily work with multiple Local sites within a single shell instance.
Local already generates a .envrc file for each site — direnv just picks it up automatically, giving you access to the site’s PHP, WP-CLI, MySQL, and Composer binaries the moment you cd in.
Note: direnv support is currently available on macOS and Linux only.
Setup
1. Install
macOS (requires Homebrew):
brew install direnv
Linux: see direnv installation docs.
2. Hook into your shell
Add to ~/.zshrc:
eval "$(direnv hook zsh)"
Other shells: direnv hook docs.
3. Whitelist your Local Sites directory (recommended)
By default, direnv requires direnv allow the first time you enter any new directory. You can skip this by using the whitelist configuration option. For example::
mkdir -p ~/.config/direnv/
touch ~/.config/direnv/config.toml
Add to config.toml (adjust path if you’ve moved your sites directory):
[whitelist]
prefix = ["~/Local Sites/"]
With those things in place, you no longer need to click the “Site Shell” button in order to work with a Local Site via the terminal.
Example session
❯ cd ~/Local\ Sites/testwpcli/app/public
direnv: loading ~/Local Sites/testwpcli/app/.envrc
direnv: export +MAGICK_CODER_MODULE_PATH +MYSQL_HOME +PHPRC +WP_CLI_CONFIG_PATH +WP_CLI_DISABLE_AUTO_CHECK_UPDATE ~PATH
❯ which wp
/Users/user.name/localdev/flywheel-local/extraResources/bin/wp-cli/posix/wp
❯ which php
/Users/user.name/Library/Application Support/Local/lightning-services/php-8.2.29+0/bin/darwin-arm64/bin/php
❯ which mysql
/Users/user.name/Library/Application Support/Local/lightning-services/mysql-8.4.0/bin/darwin-arm64/bin/mysql
❯ wp core version
7.0
❯ cd ~
direnv: unloading
❯ which wp
wp not found
Local’s .envrc (at app/.envrc, auto-generated when the site starts) looks like this:
# This file is auto-generated by Local when the site starts.
# To enable automatic shell setup, install direnv and add its shell hook:
# https://direnv.net/docs/hook.html
export MYSQL_HOME="/Users/user.name/Library/Application Support/Local/run/aIDOefgAz/conf/mysql"
export PHPRC="/Users/user.name/Library/Application Support/Local/run/aIDOefgAz/conf/php"
export WP_CLI_CONFIG_PATH="/Users/user.name/localdev/flywheel-local/extraResources/bin/wp-cli/config.yaml"
export WP_CLI_DISABLE_AUTO_CHECK_UPDATE=1
export PATH="/Users/user.name/Library/Application Support/Local/lightning-services/mysql-8.4.0/bin/darwin-arm64/bin:$PATH"
export PATH="/Users/user.name/Library/Application Support/Local/lightning-services/php-8.2.29+0/bin/darwin-arm64/bin:$PATH"
export PATH="/Users/user.name/localdev/flywheel-local/extraResources/bin/wp-cli/posix:$PATH"
export PATH="/Users/user.name/localdev/flywheel-local/extraResources/bin/composer/posix:$PATH"
export MAGICK_CODER_MODULE_PATH="/Users/user.name/Library/Application Support/Local/lightning-services/php-8.2.29+0/bin/darwin-arm64/ImageMagick/modules-Q16/coders"
You don’t need to edit it — Local manages it on site start.
