Skip to content

Releases: Thavarshan/phpvm

v1.9.0

30 Jan 10:18

Choose a tag to compare

Fixed

  • Fixed error propagation in version resolution: Commands like phpvm use latest and phpvm install latest now correctly propagate failures from phpvm_resolve_version instead of silently swallowing errors.
  • Fixed state consistency in switch_to_system_php: State file (active_version=system) is now only written AFTER the switch operation succeeds, preventing state lies when brew link operations fail.
  • Fixed apt install/uninstall symmetry: Uninstall now removes php${version}-cli, php${version}-common, and php${version}-fpm packages symmetrically with what install creates.
  • Fixed alias directory reliability: Alias directory creation is now required (not best-effort). If $PHPVM_DIR/alias cannot be created, phpvm fails with a clear error message.
  • Fixed symlink robustness: update_current_symlink now uses command -v php to resolve the actual binary path, ensuring the symlink points to what the shell would execute.
  • Fixed path traversal vulnerability in alias resolution: phpvm_resolve_version now validates alias names before file access, preventing path traversal attacks like ../../../etc/passwd.
  • Fixed path traversal vulnerability in alias commands: phpvm_alias now validates alias names BEFORE any file path operations.
  • Fixed trap restoration in sourced shells: phpvm_with_lock now explicitly clears traps with trap - SIGNAL when user had no existing trap, preventing phpvm's cleanup traps from being permanently installed in the user's shell session.
  • Fixed init ordering for help/version commands: Moved command parsing before phpvm_init_or_die so phpvm help and phpvm version work without requiring package manager detection or system initialization.
  • Fixed Linux version listing accuracy: Unified all Linux package managers (apt/dnf/yum/pacman) to use phpvm_linux_installed_versions which scans actual binaries, eliminating inaccurate package name listings like 8.2-cli or 8.2-fpm.
  • Fixed system PHP symlink consistency: System switching now calls update_current_symlink to maintain consistent $PHPVM_DIR/current symlink behavior across all switching modes.
  • Fixed alias security vulnerability: Reordered validation in phpvm_alias to validate version format before using it in file path checks, preventing potential path traversal attacks with malicious alias targets.
  • Fixed yum installation strategy: Implemented proper Remi repository detection and naming conventions (php82-php-cli format), replacing incorrect yum install php8.2 approach that would always fail.
  • Fixed lock PID staleness: Added explicit lock_pid="" reset at top of each phpvm_lock loop iteration to prevent stale PID values in error messages.
  • Fixed unversioned PHP formula detection: Homebrew's unversioned php formula is now correctly identified before any unlinking operations, preventing false version matches from system PHP.
  • Fixed phpvm which for unversioned formulas: Correctly returns path to unversioned PHP installed as php formula.
  • Fixed apt package search: pkg_search_php() now explicitly checks for Candidate: (none) to avoid false positives from apt-cache policy.
  • Fixed echo usage in input validation: Replaced echo "$var" | grep with printf '%s\n' "$var" | grep throughout to prevent interpretation of strings like -n, -e, backslash escapes.
  • Fixed phpvm_which() failure propagation: Now properly propagates failures from phpvm_current using || return $?.
  • Fixed shellcheck SC2221/SC2222 warnings: Simplified phpvm_is_sourced() case pattern to avoid overlapping matches.

Changed

  • Introduced command_exists() helper: Replaced 40+ instances of command -v X > /dev/null 2>&1 with single reusable function for cleaner command availability checks.
  • Introduced ensure_phpvm_dirs() function: Consolidated repeated mkdir -p $PHPVM_DIR/X patterns into centralized directory creation function.
  • Introduced brew_link_php_unversioned() function: Extracted duplicate brew link php --force --overwrite logic with error handling into single reusable function.
  • Introduced is_valid_version_format() function: Consolidated duplicate version regex validation pattern into single validation helper.
  • Added brew_php_major_minor() helper: Reads version directly from $HOMEBREW_PREFIX/opt/php/bin/php instead of PATH-based php -r, eliminating conflicts with system PHP.
  • Reordered version switching flow: Now resolves target formula, then unlinks all PHP, then links resolved formula, preventing "version check breaks after unlink" bugs.
  • Improved Linux binary scanning: Broadened skip patterns to prevent accidentally executing PHP helper binaries (*fpm*, *cgi*, *dbg*, *ize*, *config*).
  • Ubuntu/Debian apt packages: Changed from non-existent php8.2 to actual php8.2-cli format used by ondrej/sury PPA.
  • Fedora/RHEL dnf packages: Implemented correct module stream approach instead of fictional versioned packages.
  • Brew availability check: Changed from fragile brew search | grep to stable brew info <formula> API.
  • Trap preservation in phpvm_with_lock(): Now saves and restores user's existing trap handlers instead of clobbering them.
  • Stale lock detection and auto-cleanup: Lock mechanism now checks if lock holder PID is still running and automatically removes stale locks.

Added

  • Interactive shell guard: Auto-switch from .phpvmrc now only runs in interactive shells using case $- in *i*) pattern.
  • Test mode package manager bypass: Test mode now sets sandbox defaults without requiring actual brew/apt/dnf.

Internal

  • Bash-only support documented: Added explicit notice that script requires bash (uses bashisms).
  • Intentional symlink behavior clarified: Added comment explaining update_current_symlink() links to resolved php binary by design.
  • Dnf module stream workflow: Added inline documentation about RHEL/Fedora module stream management.
  • Version bump: Updated to v1.9.0.
  • All tests passing: 51 BATS tests pass (added 4 security tests for path traversal protection).

Full Changelog: 1.8.0...1.9.0

v1.8.0

15 Jan 20:53
d0e216d

Choose a tag to compare

Added

  • Alias management commands: Added phpvm alias and phpvm unalias for version alias creation, listing, and removal.
  • Alias pattern filtering: phpvm alias <pattern> now filters aliases by name.
  • Alias resolution support: Aliases now resolve in phpvm install, phpvm use, and phpvm which.
  • Alias visibility: phpvm list now shows configured aliases.
  • Alias resolution in .phpvmrc: phpvm auto now resolves aliases defined in .phpvmrc.
  • Latest/stable keywords: latest and stable now resolve to the latest installed PHP version.
  • Quality assurance tooling: Added ShellCheck and shfmt configuration, a QA Makefile, and a qa.sh runner script.
  • BATS test suite: Added comprehensive BATS tests for core functionality and new alias behavior.
  • CI quality workflow: Added a quality workflow for linting, formatting, and tests.

Changed

  • Help output: Promoted alias commands to the primary usage section.

Removed

  • Built-in test command: Removed phpvm test command in favor of BATS test suite only.

Internal

  • Alias helper utilities: Added alias listing helper and alias resolution logic.
  • Test coverage: Extended BATS test suite to cover alias functionality and all core features.

Full Changelog: 1.7.0...1.8.0

v1.6.0

15 Jan 20:50
1.6.0
1aa59f3

Choose a tag to compare

Added

  • Smart repository detection: Added intelligent detection of missing PHP repositories on RHEL/Fedora systems with automatic suggestions for enabling Remi's repository.
  • Enhanced error messaging: Implemented comprehensive error handling with actionable solutions when PHP packages are not found in default repositories.
  • Repository setup guidance: Added detailed step-by-step instructions for enabling EPEL and Remi repositories on Fedora, RHEL, Rocky Linux, AlmaLinux, and CentOS systems.

Changed

  • Consolidated GitHub Actions workflows: Streamlined CI/CD from 7 separate workflow files down to 3 focused workflows, eliminating duplication while maintaining comprehensive test coverage.
  • Enhanced multi-distribution testing: Expanded automated testing to cover 13 Linux distributions (Ubuntu, Debian, Fedora, Rocky Linux, AlmaLinux, Arch Linux, Alpine Linux) with 4 different package managers (apt, dnf, pacman, apk).
  • Improved cross-platform compatibility: Fixed package installation issues for RHEL-family distributions (Rocky/Alma Linux) and Alpine Linux in CI environments.
  • Streamlined workflow organization: Reorganized tests into logical categories: syntax analysis, core functionality, PHP usage, multi-distribution compatibility, performance testing, and end-to-end integration.
  • Intelligent PHP installation: Enhanced PHP installation process to check package availability before attempting installation and provide specific guidance when packages are missing.

Fixed

  • Fixed coreutils package conflicts: Resolved dnf installation conflicts in Rocky Linux and AlmaLinux by adding --allowerasing flag to handle coreutils-single vs coreutils package conflicts.
  • Fixed Alpine Linux container compatibility: Resolved bash availability issues in Alpine Linux containers by dynamically selecting appropriate shell (sh vs bash) for initial container startup.
  • Fixed virtual package installation: Resolved apt installation failure for awk virtual package by explicitly installing gawk package instead.

Removed

  • Removed emoji characters: Cleaned up all emoji usage from codebase for better terminal compatibility and professional appearance.
  • Removed redundant workflow files: Eliminated duplicate testing workflows (use.yml, comprehensive-test.yml, performance-test.yml, integration-test.yml) by consolidating functionality into main test.yml.

Full Changelog: 1.5.0...1.6.0

v1.7.0

11 Dec 16:32

Choose a tag to compare

Added

  • New phpvm current command: Display the currently active PHP version. Returns the version string, "system", or "none" depending on state.
  • New phpvm which [version] command: Show the full path to the PHP binary for a given version. Supports all package managers (brew, apt, dnf, yum, pacman).
  • New phpvm deactivate command: Temporarily disable phpvm management and restore the original PATH. Useful for debugging or temporarily using system defaults.
  • New ls alias for list: Added phpvm ls as an alias for phpvm list for convenience.
  • Specific exit codes: Implemented consistent exit codes across all commands for better scripting support:
    • 0 - Success
    • 1 - General error
    • 2 - Invalid argument or usage error
    • 3 - Version not found (not available)
    • 4 - Version not installed locally
    • 5 - File or permission error
    • 127 - Unknown command
  • Exit code documentation: Added exit codes section to help output.
  • PATH preservation: phpvm use now stores the original PATH on first activation to enable proper deactivation.

Changed

  • Enhanced help output: Updated help text with new commands, examples, and exit code documentation.
  • Improved error handling: Key functions now return specific exit codes instead of generic error codes.

Full Changelog: v1.6.0...1.7.0

v1.5.0

15 Aug 11:13
8a1339a

Choose a tag to compare

Added

  • Added comprehensive version command support: Implemented phpvm version, phpvm --version, and phpvm -v commands with detailed information including author, repository link, and usage hints.
  • Added intelligent system PHP detection: Enhanced system PHP switching to properly detect and use Homebrew's main php formula as the system default on modern macOS.
  • Added post-install validation: Added checks for PHP binary availability after installation with helpful warnings if binaries are missing.

Changed

  • Improved shebang for WSL compatibility: Changed from #!/bin/sh to #!/bin/bash for better compatibility with WSL and Linux distributions.
  • Enhanced Homebrew link failure detection: Improved detection and handling of "already linked" warnings from Homebrew with proper error reporting and user guidance.
  • Updated system PHP messaging: Changed misleading "macOS built-in PHP" references to accurate "Homebrew default PHP" messaging that reflects modern macOS reality.
  • Improved PHP version detection on Linux: Enhanced dpkg-query usage for more reliable PHP version listing on Debian/Ubuntu systems.
  • Enhanced unlinking logic: Replaced problematic wildcard unlinking with proper iteration through installed PHP formulas.

Fixed

  • Fixed false success reporting on Homebrew link failures: Script now properly detects when brew link fails due to "already linked" status and returns error instead of false success.
  • Fixed WSL script execution issues: Resolved problem where phpvm would exit silently without output on WSL/Ubuntu systems due to shell compatibility issues.
  • Fixed system PHP switching on macOS: System switching now correctly links to Homebrew's main PHP installation instead of looking for non-existent /usr/bin/php.
  • Fixed PHP version listing on Linux: Improved reliability of phpvm list command showing installed PHP versions on apt-based systems.
  • Fixed error handling for missing PHP binaries: Added proper error handling when PHP commands are not available, preventing script crashes.

v1.4.1

13 Jul 14:05
9d41d5b

Choose a tag to compare

Fixed

  • Fixed script execution detection failing on macOS/zsh: Resolved critical issue where phpvm commands (help, list, use, etc.) would run silently without any output on macOS systems using zsh shell, making the tool appear completely non-functional.
  • Fixed execution detection logic in phpvm_should_execute_main(): The original detection method incorrectly identified script execution as "sourcing" on macOS/zsh environments, causing the script to only load functions without executing the main command handler.
  • Enhanced shell compatibility with argument-based detection: Added more reliable execution detection by checking for script arguments as the primary indicator, with the original return test maintained as fallback for POSIX shell compatibility.
  • Improved detection layer ordering: Reorganized execution detection logic to prioritize more reliable methods (argument presence) over shell-specific tests that behave inconsistently across different environments.

New Contributors

Full Changelog: 1.4.0...1.4.1

v1.4.0

23 Jun 05:13
d6e06dd

Choose a tag to compare

Added

  • Uninstall Command: New phpvm uninstall <version> command to remove installed PHP versions

    • Supports all package managers: Homebrew, APT, DNF, YUM, Pacman
    • Automatically detects installed packages before attempting removal
    • Smart cleanup of symlinks and active version when uninstalling currently active PHP
    • Includes comprehensive test mode support with mock package databases
    • Provides clear warnings when attempting to uninstall non-existent versions
  • Enhanced Shell Integration: Improved sourcing support with automatic .phpvmrc detection

    • Sets PHPVM_FUNCTIONS_LOADED=true environment variable when sourced
    • Auto-switches PHP version based on .phpvmrc when script is sourced (configurable via PHPVM_AUTO_USE)
    • Better function availability detection for shell integration
  • Advanced Execution Control: New PHPVM_SOURCED environment variable for explicit execution control

    • Supports true/1/yes to force sourcing mode
    • Supports false/0/no to force execution mode
    • Provides override mechanism for edge cases and automation

Changes

  • Robust POSIX Compliance: Complete rewrite of execution detection logic

    • Replaced bash-specific [[ "${BASH_SOURCE[0]}" == "${0}" ]] with 3-layer POSIX detection
    • Layer 1: Explicit override via PHPVM_SOURCED environment variable
    • Layer 2: Test mode detection (PHPVM_TEST_MODE)
    • Layer 3: POSIX-compliant return test (return 0 2>/dev/null)
    • Now works reliably on Ubuntu/Mint systems using dash shell (/bin/sh)
  • Enhanced Error Handling: Improved function validation and debugging

    • Added function existence checks before execution
    • Better error messages with script corruption detection
    • Enhanced debug logging throughout execution flow
  • Improved Test Infrastructure: Extended mock system for uninstall testing

    • Package manager-specific mock directories for test mode
    • Better package detection simulation across different systems
    • More comprehensive test coverage for edge cases

Fixed

  • Ubuntu/Mint Compatibility: Resolved "Bad substitution" errors on systems using dash shell

    • Issue occurred when /bin/sh pointed to dash instead of bash
    • Script now fully POSIX-compliant and works across all Unix-like systems
    • No more dependency on bash-specific features
  • Shell Sourcing Reliability: Fixed inconsistent behavior when sourcing script

    • Improved detection of sourced vs executed context
    • Better handling of edge cases in different shell environments
    • More predictable behavior across bash, dash, zsh, and other POSIX shells
  • Package Manager Detection: Enhanced validation for uninstall operations

    • Better regex patterns for package detection across different package managers
    • Improved error handling for package manager-specific commands
    • More accurate installed package verification before removal attempts

v1.3.0

11 May 11:54
9aa8aa5

Choose a tag to compare

Added

  • Added system command to easily switch back to system PHP version
  • Added timestamps to all log messages for better traceability and debugging
  • Added log levels (INFO, ERROR, WARNING, DEBUG) for more structured logging
  • Added run_with_sudo helper function to centralize sudo usage logic
  • Added comprehensive self-tests with phpvm test command
  • Added test for corrupted .phpvmrc file handling
  • Added better support for detecting and using latest PHP version from Homebrew
  • Added improved error messages with more detailed information
  • Added ability to run self-tests with phpvm test command
  • Added debugging capability via DEBUG=true environment variable

Changed

  • Changed logging format to include timestamps and log levels
  • Changed sudo handling to use a centralized helper function
  • Changed path expansion to use $HOME instead of tilde notation for better compatibility
  • Changed error handling to provide more descriptive and actionable messages
  • Changed test framework to be integrated directly into the script
  • Changed help message to include information about the test command
  • Improved bash/zsh shell compatibility with better sourcing logic
  • Improved code organization and reduced duplication with helper functions

Fixed

  • Fixed shell crash issue when sourcing in zsh with p10k theme
  • Fixed path expansion issues in Ubuntu bashrc configurations
  • Fixed missing system PHP switching functionality on macOS
  • Fixed detection of latest PHP version on macOS when installed via Homebrew's generic 'php' formula
  • Fixed potential sudo permission issues on Linux by using run_with_sudo consistently
  • Fixed auto-switching edge case with invalid or corrupted .phpvmrc files
  • Fixed script execution issues when sourced from shell initialization files
  • Fixed various edge cases in version detection and switching

Full Changelog: 1.2.0...1.3.0

v1.2.0

15 Feb 05:57

Choose a tag to compare

Added

  • GitHub Actions CI/CD Integration: Added workflows for running automated tests and verifying PHPVM functionality on macOS and Linux.
  • Linux Compatibility: Implemented Homebrew mock support to allow testing on both macOS and Linux environments.
  • Extended Test Suite: Improved BATS test coverage to handle different system environments and dependencies.

Changed

  • Improved Homebrew Detection: The script now properly checks for Homebrew availability and handles missing installations more gracefully.
  • Refactored Test Setup: The setup function in test_phpvm.bats now ensures correct sourcing of phpvm.sh and mocks Homebrew on Linux.
  • Better Error Messages: Adjusted error outputs for clarity when Homebrew or PHP versions are unavailable.

Fixed

  • Fixed Ubuntu Compatibility Issues: The tests no longer fail due to missing Homebrew; instead, they mock Homebrew behavior on Linux.
  • Resolved Test Failures: The install_php, use_php_version, and auto_switch_php_version tests now properly execute across different OS platforms.
  • Prevented Test Cleanup Failures: The teardown function now ensures .phpvmrc and other temporary files are removed only if they exist.

Full Changelog: 1.1.0...1.2.0

v1.1.0

09 Feb 17:47
d28a8a2

Choose a tag to compare

Added

  • Added comprehensive error handling to the main phpvm script for robust operations.
  • Added checks for command availability (e.g., curl) in the installation script.
  • Added a suite of unit tests using BATS, allowing automated testing of core functionalities.
  • Added clear and informative, color-coded terminal messages for user interactions.

Changed

  • Enhanced the installation script to safely modify user shell profiles and avoid duplicate entries.
  • Updated the main phpvm script to use strict mode (set -euo pipefail) for improved reliability.
  • Improved overall error reporting to capture and relay issues during directory creation, downloading, and file permission changes.

Fixed

  • Fixed various shellcheck warnings/errors such as SC2034 (unused variables), SC2086 (unquoted variables), SC2155 (variable declaration), and SC2128 (array handling).
  • Fixed potential issues with word splitting and globbing by ensuring proper quoting of variables in command calls.

Full Changelog: 1.0.0...1.1.0