A fast, feature-rich PHP version manager for Fish Shell that acts like goenv or nvm.
- Fast version detection (100-1000x faster than
brew list) - Dynamic version resolution from shivammathur/setup-php
- Multiple version sources:
.php-version,.tool-version,composer.json - Auto-installation of missing PHP versions
- Extension management with availability checking
- Composer.json integration with full semver support
- Auto-switching between versions (configurable)
- Fisher package manager support
- Rich completions with descriptions
fisher install ivuorinen/phpenv.fish-
Copy files to your fish configuration:
# Functions curl -L https://raw.githubusercontent.com/ivuorinen/phpenv.fish/main/functions/phpenv.fish > ~/.config/fish/functions/phpenv.fish # Completions curl -L https://raw.githubusercontent.com/ivuorinen/phpenv.fish/main/completions/phpenv.fish > ~/.config/fish/completions/phpenv.fish # Configuration curl -L https://raw.githubusercontent.com/ivuorinen/phpenv.fish/main/conf.d/phpenv.fish > ~/.config/fish/conf.d/phpenv.fish
-
Install dependencies:
brew install jq
-
Add Homebrew taps:
brew tap shivammathur/php brew tap shivammathur/extensions
# Show available versions
phpenv versions
# Install PHP versions
phpenv install 8.3
phpenv install 8.1
# Set global default
phpenv global 8.3
# Set project-specific version
phpenv local 8.1
# Install extensions
phpenv extensions install xdebug
phpenv extensions install redis
# Configure behavior
phpenv config set auto-switch false # Disable auto-switching
phpenv config set auto-install true # Enable auto-installation
# Check installation
phpenv doctorphpenv install <version>- Install PHP versionphpenv uninstall <version>- Uninstall PHP versionphpenv use <version>- Use version for current shellphpenv local <version>- Set version for current projectphpenv global <version>- Set global default versionphpenv list- List installed versionsphpenv current- Show current versionphpenv versions- Show all available versions
phpenv extensions install <ext>- Install extension for current PHPphpenv extensions uninstall <ext>- Uninstall extensionphpenv extensions list- List installed extensionsphpenv extensions available- Show available extensions
phpenv config get <key>- Get configuration valuephpenv config set <key> <value>- Set configuration valuephpenv config list- List all configuration
phpenv which [binary]- Show path to PHP binaryphpenv doctor- Check installation healthphpenv help- Show help
phpenv automatically detects PHP versions from multiple sources (in priority order):
.php-version- Project-specific version file.tool-version- Tool version file (parsesv8.4as8.4)composer.json- Bothconfig.platform.phpandrequire.phpwith semver support- Global version - Fish universal variable
- System PHP - Fallback to system installation
Supports all semver constraints:
^8.1→ Uses PHP 8.3 (latest 8.x)~8.2.0→ Uses PHP 8.2>=8.0→ Uses PHP 8.38.1.*→ Uses PHP 8.1
Checks both locations:
{
"require": {
"php": "^8.1"
},
"config": {
"platform": {
"php": "8.2.0"
}
}
}auto-install- Auto-install missing versions (default: false)auto-install-extensions- Install extensions with new PHP versions (default: false)auto-switch- Auto-switch versions when changing directories (default: true)default-extensions- Space-separated list of default extensions (default: "opcache")global-version- Global PHP version
phpenv checks these locations (in order):
~/.config/fish/conf.d/phpenv.fish(preferred)~/.config/phpenv/config~/.phpenv.fish
# Enable auto-installation
phpenv config set auto-install true
# Disable auto-switching
phpenv config set auto-switch false
# Set default extensions
phpenv config set default-extensions "opcache xdebug redis"
# Enable auto-extension installation
phpenv config set auto-install-extensions trueUses shivammathur/homebrew-php with dynamic version detection:
Version Aliases:
latest- Latest stable PHP versionnightly- Development version8.x- Latest PHP 8.x version7.x- Latest PHP 7.x version5.x- Latest PHP 5.x version
Available Versions: 5.6, 7.0-7.4, 8.0-8.5
Uses shivammathur/homebrew-extensions:
- xdebug, redis, imagick, mongodb, memcached
- pcov, ast, grpc, protobuf, yaml
- And many more...
- Directory checks: ~1-5ms (vs ~1000ms for
brew list) - Bulk version detection: ~10ms for all versions
- No Ruby overhead or git operations
- Efficient caching and lazy loading
phpenv automatically switches PHP versions when you change directories if a version file is detected in the project.
Works seamlessly with Fisher package manager:
# Install
fisher install ivuorinen/phpenv.fish
# Update
fisher update ivuorinen/phpenv.fish
# Uninstall
fisher remove ivuorinen/phpenv.fishphpenv doctorbrew install jq# Add taps manually
brew tap shivammathur/php
brew tap shivammathur/extensions
# Install specific version
phpenv install 8.3- phpenv is designed to be fast by avoiding
brew list - If performance issues persist, check your filesystem or try
phpenv doctor
# Check current detection
phpenv current
# Check which binary is used
phpenv which php
# List all configuration
phpenv config listContributions welcome! Please see CONTRIBUTING.md for detailed guidelines.
Quick Guidelines:
- Follow fish shell best practices
- Add tests for new functionality
- Update documentation
- Maintain performance optimizations
- Run pre-commit hooks before submitting
Development Setup:
# Link development version to Fish config
ln -sf $PWD/functions/phpenv.fish ~/.config/fish/functions/phpenv.fish
ln -sf $PWD/completions/phpenv.fish ~/.config/fish/completions/phpenv.fish
ln -sf $PWD/conf.d/phpenv.fish ~/.config/fish/conf.d/phpenv.fish
# Install pre-commit hooks
pip install pre-commit
pre-commit installphpenv.fish is designed for speed and efficiency:
- API Data Caching: Version information cached for 5 minutes
- Homebrew Path Caching: Cellar path permanently cached
- Smart Debouncing: Auto-switching limited to prevent excessive PATH changes
- Consolidated jq Parsing: Single function eliminates repeated API calls
- Unified Tap Management: Shared logic for Homebrew tap operations
- Optimized Formula Listing: Cached and shared across operations
- 100-1000x faster than
brew listfor version detection - Direct directory checks instead of subprocess calls
- Minimal network requests with intelligent caching
MIT License - see LICENSE file for details.