Bug Summary
Local’s auto-generated .envrc exports PHPRC and MAGICK_CODER_MODULE_PATH into the shell environment via direnv, causing any external PHP-based CLI tool (e.g. Terminus, Pantheon’s CLI) to load Local’s PHP configuration instead of the system PHP configuration, resulting in extension load failures and broken network connectivity.
Steps to reproduce
- Install direnv and configure its shell hook ( Setup | direnv )
- Start a Local site — Local auto-generates a
.envrcfile in the site directory cdinto the site directory (direnv automatically loads.envrcinto the shell environment)- Run any external PHP-based CLI tool — in my case,
terminus env:clear-cache <sitename.env>
Environment Info
- OS: macOS 26.5.1 (Tahoe)
- Local version: Version 10.1.1+6939
- Site PHP: 8.3.30
- System PHP (Homebrew): 8.5.7
- Web server: nginx
- MySQL: 8.0.35
Supporting info
The root cause: Local’s .envrc sets PHPRC to Local’s PHP configuration directory. When an external tool invokes system PHP (8.5), it loads Local’s php.ini, which references extensions compiled for PHP 8.3. This produces errors like:
Failed loading opcache.so: symbol not found in flat namespace '_zend_observer_fcall_end'
Xdebug requires Zend Engine API version 420230831. The version 420250925 which is installed is newer.
Warning: Unable to load dynamic library 'imagick.so'
These extension failures corrupt PHP’s runtime and break outbound HTTP — producing “Connection refused” errors against external APIs with no indication that a PHP misconfiguration is the cause.
Workaround: A wrapper script that clears the offending variables before invoking the external tool:
#!/bin/zsh
env PATH="/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin" \
PHPRC="" \
MAGICK_CODER_MODULE_PATH="" \
/opt/homebrew/bin/terminus "$@"
Suggested fix: PHPRC and MAGICK_CODER_MODULE_PATH should not be exported into the general shell environment. These variables are only meaningful within Local’s own PHP runtime. Scoping them to Local’s internal WP-CLI context only would prevent them from leaking into the developer’s interactive shell and breaking other tools.
At minimum, the .envrc feature’s documentation should warn direnv users of this side effect. At MINIMUM minimum, creating a .envrc / using direnv should be able to be disabled through the preferences.
