This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
phpvm is a lightweight PHP Version Manager for macOS and Linux that enables easy installation, switching, and management of multiple PHP versions via command line. The project is built as a single, comprehensive bash script with extensive cross-platform compatibility.
-
phpvm.sh- Main functionality (1000+ lines of bash)- PHP version installation and management
- Cross-platform package manager detection
- Version switching with symlink management
- Auto-switching based on
.phpvmrcfiles - Built-in comprehensive test suite
-
install.sh- Installation script- Downloads and sets up phpvm
- Configures shell profile integration
- Handles different shell types (bash/zsh)
-
versions/- Directory for PHP version metadata (currently empty)
The tool detects and works with multiple package managers:
- macOS: Homebrew (
brew) - Linux: apt, dnf, yum, pacman
- Linuxbrew: Supported on Linux systems
- Install PHP versions using system package managers
- Switch between installed versions using symlinks and package manager tools
- System PHP fallback support
- Active version tracking via
~/.phpvm/active_version
- Detects
.phpvmrcfiles in current/parent directories (up to 5 levels) - Automatically switches to specified PHP version
- Handles corrupted/invalid
.phpvmrcfiles gracefully
- BATS (Bash Automated Testing System) test suite in
tests/directory - Mock environment creation for testing with
PHPVM_TEST_MODE=true - Comprehensive test coverage including edge cases
- Run tests with:
bats tests/
- POSIX-compliant bash scripting where possible
- Comprehensive error handling with structured logging
- Timestamped log messages with levels (INFO, ERROR, WARNING, DEBUG)
- Helper functions to reduce code duplication
- Run tests:
bats tests/ - Tests create isolated mock environments with
PHPVM_TEST_MODE=true - All core functionality is tested including error conditions
- Tests verify cross-platform compatibility
- GitHub Actions runs automated tests on Ubuntu and macOS
- Shell syntax checking with
bash -n phpvm.sh - ShellCheck static analysis for code quality
- Enable debug mode:
PHPVM_DEBUG=true phpvm <command> - Debug logs provide detailed execution tracing
- Test mode can be enabled with
PHPVM_TEST_MODE=true
- Add command handler in the
main()function case statement - Implement the command function following naming convention
command_name() - Add help text in
print_help() - Add BATS tests in the
tests/directory
- Add detection logic in
detect_system() - Add installation logic in
install_php() - Add version switching logic in
use_php_version() - Add version listing logic in
list_installed_versions() - Add uninstall logic in
uninstall_php()
# Run all tests
bats tests/
# Run specific test file
bats tests/01_core.bats
# Enable debug mode for troubleshooting
PHPVM_DEBUG=true bats tests/
# Test specific functionality manually with test mode
PHPVM_TEST_MODE=true PHPVM_DEBUG=true ./phpvm.sh install 8.1
PHPVM_TEST_MODE=true PHPVM_DEBUG=true ./phpvm.sh use 8.1
# Check shell syntax
bash -n phpvm.sh
bash -n install.sh
# Run performance checks
time ./phpvm.sh version
time ./phpvm.sh helpConventions: tag = X.Y.Z (no v prefix), title = vX.Y.Z (with v prefix).
- Bump version in
PHPVM_VERSIONvariable at the top ofphpvm.sh - Update CHANGELOG.md — add a new section under
[Unreleased]following the existing format:Use subsections:## [vX.Y.Z](https://github.com/Thavarshan/phpvm/compare/vPREV...vX.Y.Z) - YYYY-MM-DD### Fixed,### Changed,### Removed,### Internalas needed. - Verify syntax and tests pass:
bash -n phpvm.sh bats tests/
- Commit and push:
git add phpvm.sh CHANGELOG.md git commit -m "chore: release vX.Y.Z — short description" git push origin main - Create GitHub release (triggers the
release.ymlworkflow):Or usegh release create X.Y.Z --title "vX.Y.Z" --notes-file /path/to/notes.md--notes "..."for short notes. Prefer--notes-filefor multi-line content to avoid shell quoting issues. - Update README.md if needed (new features, changed env vars, etc.)
main()- Entry point with command routingdetect_system()- Package manager and OS detectioninstall_php()- PHP version installation logicuse_php_version()- Version switching functionalityfind_phpvmrc()- Auto-detection of .phpvmrc files- Helper functions:
run_with_sudo(),phpvm_echo(),phpvm_err(),phpvm_warn(),phpvm_debug() - Package manager abstraction:
pkg_install_php(),pkg_uninstall_php(),pkg_search_php()
phpvm/
├── CLAUDE.md # This file
├── CHANGELOG.md # Release history
├── LICENSE # MIT license
├── README.md # User documentation
├── TESTING.md # Testing documentation (minimal)
├── assets/ # Project images
├── install-bats.sh # BATS installation script
├── install.sh # Main installation script
├── phpvm.sh # Core functionality (~1000 lines)
├── versions/ # Version metadata directory
└── .github/ # GitHub workflows and templates
└── workflows/
├── test.yml # Automated testing
├── use.yml # Usage testing
└── release.yml # Release automation
PHPVM_DIR- Installation directory (default:~/.phpvm)PHPVM_DEBUG- Enable debug logging (set totrue)PHPVM_TEST_MODE- Enable test mode (set totrue)PHPVM_SOURCED- Control execution vs sourcing behaviorPHPVM_AUTO_USE- Enable automatic.phpvmrcdetection (default:true)
- Relies on Homebrew for PHP installation
- Uses
brew link/unlinkfor version switching - Handles Homebrew prefix detection automatically
- Supports multiple package managers
- Uses
update-alternativesfor version switching where available - Requires
sudoprivileges for system-level operations
- Works with bash and zsh
- POSIX-compliant where possible
- Handles different shell profile files (.bashrc, .zshrc, .profile)
- Uses
run_with_sudo()helper for controlled privilege escalation - Validates input parameters before system operations
- No hardcoded credentials or sensitive data
- Safe handling of temporary files and directories
- Lightweight single-script architecture
- Minimal external dependencies
- Fast execution due to bash implementation
- Efficient directory traversal for
.phpvmrcdetection