Tools: PVM - PHP Version Manager for Windows

Tools: PVM - PHP Version Manager for Windows

Source: Dev.to

What is PVM ? ## Project Structure Overview ## Key Features ## Prerequisites ## Installation & Setup ## Step 1: Clone the Repository ## Step 2: Automated Setup ## Command Reference ## Getting Help ## Display information about the environment ## Checking Current Version ## Listing PHP Versions ## Installing PHP Versions ## Uninstalling PHP Versions ## Switching Between Versions ## PHP Configuration Management ## Extension Management ## PHP Settings Management ## Manage PHP Configuration Profiles ## Running Tests ## Requirements ## Run the tests ## Logging and Storage System ## Key Files ## Final Thoughts Managing multiple PHP versions on Windows has traditionally been a challenging task for developers. Enter PVM (PHP Version Manager), a command-line tool specifically designed to simplify PHP version management on Windows systems. This comprehensive guide will walk you through everything you need to know about PVM, from installation to advanced usage. PVM is a powerful, command-line PHP version manager built specifically for Windows environments, it addresses the unique challenges Windows developers face when working with multiple PHP versions. What sets PVM apart is its comprehensive approach - it doesn't just manage PHP versions, but also handles extensions, php.ini configurations, and environment variables seamlessly. PVM follows a well-organized structure that separates concerns and maintains clean code architecture: Automated Setup Process: PVM now includes an intelligent setup command that handles PATH variable configuration automatically, eliminating manual environment setup. Seamless Version Switching: Switch between PHP versions with a single command, making it easy to test applications across different PHP environments. Extension Management: Built-in support for popular extensions like Xdebug and OPcache, with the ability to enable or disable them per installation. Direct php.ini Management: Modify PHP settings and manage extensions directly from the command line without manually editing configuration files. Custom Installation Directories: Install PHP versions in custom locations to suit your specific development setup. Online Version Discovery: Fetch available PHP versions directly from online sources, ensuring you always have access to the latest releases. Configuration Backup and Restore: Automatic backup of PATH variables and php.ini settings with easy restoration options. Getting started with PVM has been significantly simplified with the new automated setup process: First, clone the PVM repository to your local machine: Run the setup command to automatically configure PVM: The setup process automatically: PVM provides a comprehensive set of commands for managing your PHP installations and configurations: Display all available commands and their descriptions, serving as your quick reference guide. Display help for a specific command with description, usage and examples Display information about the current PHP (version, path, extensions, settings) Display information about the current PHP extensions Display information about the current PHP settings Display information about the current PHP (version, path, extensions, settings) with specific in their name Shows which PHP version is currently active on your system. Display all PHP versions currently installed on your system. List installed versions with specific version in the name View all PHP versions available for installation from your configured sources. List available versions with specific version in the name Install a specific PHP version. Replace <version> with the desired version number (e.g., 7.4.33 or 8.2.0). Remove a specific PHP version from your system cleanly, including all associated files and configurations. Switch your active PHP version to the specified version, updating all necessary environment variables automatically. When run inside a PHP project, this command checks for a .php-version file and composer.json, then switches to the PHP version specified in either file. One of PVM's most powerful features is its ability to manage PHP configurations and extensions directly from the command line: Check extensions status: Set Configuration Values and change the status: Get Configuration Values: Install extensions from remote source List installed extensions List available extensions from remote source List installed extensions with 'zip' in their name List available extensions with 'zip' in their name Restore Configuration: Restore php.ini settings from backup, useful when you need to revert changes or start fresh. This one will help you check the log file in a readable way, with pagination. Save, load, and share PHP settings and extensions using JSON profiles: Profile Structure: Profiles are stored as JSON files in storage/data/profiles/ and contain: Note: Only popular/common settings and extensions are saved in profiles. This keeps profiles focused and manageable. Run tests against the PowerShell scripts in the repo — especially useful for contributors verifying changes before submitting a pull request: To run tests with, you need to have the Pester testing framework installed. Pester is a testing framework for PowerShell. Open PowerShell as Administrator and run: 💡 If prompted to trust the repository, type Y and press Enter. You can verify the installation with: PVM maintains essential files for troubleshooting and performance: Error Logging: storage/logs/error.log PATH Backup: storage/logs/path.bak.log variables need restoration Available Versions Cache for faster performance: PVM dramatically simplifies PHP version management on Windows, offering a seamless and developer-friendly experience that was long missing from the ecosystem. With its powerful command-line tools, automated setup, and deep integration with extensions and configuration files, PVM empowers developers to focus more on building applications. Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse COMMAND_BLOCK: pvm/ ├── pvm.bat # Main executable entry point ├── src/ │ ├── actions/ # Core functionality modules │ │ ├── setup.ps1 # Installation and setup logic │ │ ├── install.ps1 # PHP version installation │ │ ├── use.ps1 # Version switching logic │ │ ├── ini.ps1 # PHP configuration management │ │ └── ... # Other action modules │ ├── core/ # Core system components │ │ ├── config.ps1 # Configuration management │ │ └── router.ps1 # Command routing logic │ ├── functions/ # Utility functions │ └── pvm.ps1 # Main PowerShell entry point └── tests/ # Test suite directory (Pester tests) └── storage/ # Data and logging directory ├── data/ # Cached data and configurations ├── logs/ # Error logs and backups └── php/ # PHP installations directory Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm/ ├── pvm.bat # Main executable entry point ├── src/ │ ├── actions/ # Core functionality modules │ │ ├── setup.ps1 # Installation and setup logic │ │ ├── install.ps1 # PHP version installation │ │ ├── use.ps1 # Version switching logic │ │ ├── ini.ps1 # PHP configuration management │ │ └── ... # Other action modules │ ├── core/ # Core system components │ │ ├── config.ps1 # Configuration management │ │ └── router.ps1 # Command routing logic │ ├── functions/ # Utility functions │ └── pvm.ps1 # Main PowerShell entry point └── tests/ # Test suite directory (Pester tests) └── storage/ # Data and logging directory ├── data/ # Cached data and configurations ├── logs/ # Error logs and backups └── php/ # PHP installations directory COMMAND_BLOCK: pvm/ ├── pvm.bat # Main executable entry point ├── src/ │ ├── actions/ # Core functionality modules │ │ ├── setup.ps1 # Installation and setup logic │ │ ├── install.ps1 # PHP version installation │ │ ├── use.ps1 # Version switching logic │ │ ├── ini.ps1 # PHP configuration management │ │ └── ... # Other action modules │ ├── core/ # Core system components │ │ ├── config.ps1 # Configuration management │ │ └── router.ps1 # Command routing logic │ ├── functions/ # Utility functions │ └── pvm.ps1 # Main PowerShell entry point └── tests/ # Test suite directory (Pester tests) └── storage/ # Data and logging directory ├── data/ # Cached data and configurations ├── logs/ # Error logs and backups └── php/ # PHP installations directory COMMAND_BLOCK: git clone https://github.com/drissboumlik/pvm cd pvm Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: git clone https://github.com/drissboumlik/pvm cd pvm COMMAND_BLOCK: git clone https://github.com/drissboumlik/pvm cd pvm CODE_BLOCK: pvm setup Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: pvm help Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm help <command> # Example : pvm help use Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm help <command> # Example : pvm help use COMMAND_BLOCK: pvm help <command> # Example : pvm help use CODE_BLOCK: pvm info pvm ini info Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: pvm info pvm ini info CODE_BLOCK: pvm info pvm ini info COMMAND_BLOCK: pvm info extensions # pvm ini info extensions Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm info extensions # pvm ini info extensions COMMAND_BLOCK: pvm info extensions # pvm ini info extensions COMMAND_BLOCK: pvm info settings # pvm ini info settings Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm info settings # pvm ini info settings COMMAND_BLOCK: pvm info settings # pvm ini info settings COMMAND_BLOCK: pvm info --search=<term> # pvm ini info --search=<term> # Example : pvm info --search=cache Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm info --search=<term> # pvm ini info --search=<term> # Example : pvm info --search=cache COMMAND_BLOCK: pvm info --search=<term> # pvm ini info --search=<term> # Example : pvm info --search=cache CODE_BLOCK: pvm current Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: pvm current CODE_BLOCK: pvm current COMMAND_BLOCK: pvm list # pvm ls Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm list # pvm ls COMMAND_BLOCK: pvm list # pvm ls COMMAND_BLOCK: pvm list --search=<version> # Example: pvm list --search=8.2 Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm list --search=<version> # Example: pvm list --search=8.2 COMMAND_BLOCK: pvm list --search=<version> # Example: pvm list --search=8.2 COMMAND_BLOCK: pvm list available # pvm ls available Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm list available # pvm ls available COMMAND_BLOCK: pvm list available # pvm ls available COMMAND_BLOCK: pvm list available --search=<version> # Example: pvm list available --search=8.2 Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm list available --search=<version> # Example: pvm list available --search=8.2 COMMAND_BLOCK: pvm list available --search=<version> # Example: pvm list available --search=8.2 COMMAND_BLOCK: pvm install <version> # pvm i <version> # Example: pvm install 8.4 / pvm i 8.4 Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm install <version> # pvm i <version> # Example: pvm install 8.4 / pvm i 8.4 COMMAND_BLOCK: pvm install <version> # pvm i <version> # Example: pvm install 8.4 / pvm i 8.4 COMMAND_BLOCK: pvm install auto # pvm i auto # Install the php version specified on your project. Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm install auto # pvm i auto # Install the php version specified on your project. COMMAND_BLOCK: pvm install auto # pvm i auto # Install the php version specified on your project. COMMAND_BLOCK: pvm uninstall <version> # pvm rm <version> # Example: pvm uninstall 8.4 # pvm rm 8.4 Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm uninstall <version> # pvm rm <version> # Example: pvm uninstall 8.4 # pvm rm 8.4 COMMAND_BLOCK: pvm uninstall <version> # pvm rm <version> # Example: pvm uninstall 8.4 # pvm rm 8.4 COMMAND_BLOCK: pvm use <version> # Example: pvm use 8.4 Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm use <version> # Example: pvm use 8.4 COMMAND_BLOCK: pvm use <version> # Example: pvm use 8.4 CODE_BLOCK: pvm use auto Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: pvm use auto CODE_BLOCK: pvm use auto COMMAND_BLOCK: pvm ini status <extension> # Example: pvm ini status xdebug opcache Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm ini status <extension> # Example: pvm ini status xdebug opcache COMMAND_BLOCK: pvm ini status <extension> # Example: pvm ini status xdebug opcache COMMAND_BLOCK: pvm ini enable xdebug opcache # Example: pvm ini enable xdebug opcache Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm ini enable xdebug opcache # Example: pvm ini enable xdebug opcache COMMAND_BLOCK: pvm ini enable xdebug opcache # Example: pvm ini enable xdebug opcache COMMAND_BLOCK: pvm ini disable xdebug opcache # Example: pvm ini disable xdebug opcache Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm ini disable xdebug opcache # Example: pvm ini disable xdebug opcache COMMAND_BLOCK: pvm ini disable xdebug opcache # Example: pvm ini disable xdebug opcache COMMAND_BLOCK: pvm ini set <setting>=<value> [--disable] # Default is enabling the setting # Example: pvm ini set memory_limit=512M max_file_uploads=20 # Example: pvm ini set max_input_time=60 --disable Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm ini set <setting>=<value> [--disable] # Default is enabling the setting # Example: pvm ini set memory_limit=512M max_file_uploads=20 # Example: pvm ini set max_input_time=60 --disable COMMAND_BLOCK: pvm ini set <setting>=<value> [--disable] # Default is enabling the setting # Example: pvm ini set memory_limit=512M max_file_uploads=20 # Example: pvm ini set max_input_time=60 --disable COMMAND_BLOCK: pvm ini get <setting> # Example: pvm ini get memory_limit max_file_uploads Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm ini get <setting> # Example: pvm ini get memory_limit max_file_uploads COMMAND_BLOCK: pvm ini get <setting> # Example: pvm ini get memory_limit max_file_uploads COMMAND_BLOCK: pvm ini install <extension> # Example: pvm ini install opcache Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm ini install <extension> # Example: pvm ini install opcache COMMAND_BLOCK: pvm ini install <extension> # Example: pvm ini install opcache CODE_BLOCK: pvm ini list Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: pvm ini list CODE_BLOCK: pvm ini list CODE_BLOCK: pvm ini list available Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: pvm ini list available CODE_BLOCK: pvm ini list available COMMAND_BLOCK: pvm ini list --search=<extension> # Example: pvm ini list --search=zip Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm ini list --search=<extension> # Example: pvm ini list --search=zip COMMAND_BLOCK: pvm ini list --search=<extension> # Example: pvm ini list --search=zip COMMAND_BLOCK: pvm ini list available --search=<extension> # Example: pvm ini list available --search=zip Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm ini list available --search=<extension> # Example: pvm ini list available --search=zip COMMAND_BLOCK: pvm ini list available --search=<extension> # Example: pvm ini list available --search=zip CODE_BLOCK: pvm ini restore Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: pvm ini restore CODE_BLOCK: pvm ini restore COMMAND_BLOCK: pvm log --pageSize=[number] # Default value is 5 Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm log --pageSize=[number] # Default value is 5 COMMAND_BLOCK: pvm log --pageSize=[number] # Default value is 5 COMMAND_BLOCK: # Save current PHP configuration to a profile pvm profile save <name> [description] # Example: pvm profile save development # Example: pvm profile save production "Production configuration" # Load and apply a saved profile pvm profile load <name> # Example: pvm profile load development # List all available profiles pvm profile list # Show detailed profile contents pvm profile show <name> # Example: pvm profile show development # Delete a profile pvm profile delete <name> # Example: pvm profile delete old-profile # Export profile to a JSON file pvm profile export <name> [path] # Example: pvm profile export development # Example: pvm profile export dev ./backup.json # Import profile from a JSON file pvm profile import <path> [name] # Example: pvm profile import ./my-profile.json # Example: pvm profile import ./profile.json custom-name Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: # Save current PHP configuration to a profile pvm profile save <name> [description] # Example: pvm profile save development # Example: pvm profile save production "Production configuration" # Load and apply a saved profile pvm profile load <name> # Example: pvm profile load development # List all available profiles pvm profile list # Show detailed profile contents pvm profile show <name> # Example: pvm profile show development # Delete a profile pvm profile delete <name> # Example: pvm profile delete old-profile # Export profile to a JSON file pvm profile export <name> [path] # Example: pvm profile export development # Example: pvm profile export dev ./backup.json # Import profile from a JSON file pvm profile import <path> [name] # Example: pvm profile import ./my-profile.json # Example: pvm profile import ./profile.json custom-name COMMAND_BLOCK: # Save current PHP configuration to a profile pvm profile save <name> [description] # Example: pvm profile save development # Example: pvm profile save production "Production configuration" # Load and apply a saved profile pvm profile load <name> # Example: pvm profile load development # List all available profiles pvm profile list # Show detailed profile contents pvm profile show <name> # Example: pvm profile show development # Delete a profile pvm profile delete <name> # Example: pvm profile delete old-profile # Export profile to a JSON file pvm profile export <name> [path] # Example: pvm profile export development # Example: pvm profile export dev ./backup.json # Import profile from a JSON file pvm profile import <path> [name] # Example: pvm profile import ./my-profile.json # Example: pvm profile import ./profile.json custom-name CODE_BLOCK: Install-Module -Name Pester -Force -SkipPublisherCheck Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: Install-Module -Name Pester -Force -SkipPublisherCheck CODE_BLOCK: Install-Module -Name Pester -Force -SkipPublisherCheck CODE_BLOCK: Get-Module -ListAvailable Pester Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: Get-Module -ListAvailable Pester CODE_BLOCK: Get-Module -ListAvailable Pester COMMAND_BLOCK: pvm test [files = (files inside the tests/ directory)] [--coverage[=<number>]] [--verbosity=(None|Normal|Detailed|Diagnostic)] [--tag=<tag>] # Examples: pvm test # .............................. Runs all tests with Normal (default) verbosity. pvm test use install # .................. Runs only 'use.tests.ps1' and 'install.tests.ps1' files with Normal verbosity. pvm test --verbosity=Detailed # ......... Runs all tests with Detailed verbosity. pvm test --coverage # ................... Runs all tests and generates coverage report (target: 75%) pvm test --coverage=80.5 # .............. Runs all tests and generates coverage report (target: 80.5%) pvm test --tag=myTag #................... Runs helpers.tests.ps1 and list.tests.ps1 with Diagnostic verbosity and only runs tests with tag "myTag". Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pvm test [files = (files inside the tests/ directory)] [--coverage[=<number>]] [--verbosity=(None|Normal|Detailed|Diagnostic)] [--tag=<tag>] # Examples: pvm test # .............................. Runs all tests with Normal (default) verbosity. pvm test use install # .................. Runs only 'use.tests.ps1' and 'install.tests.ps1' files with Normal verbosity. pvm test --verbosity=Detailed # ......... Runs all tests with Detailed verbosity. pvm test --coverage # ................... Runs all tests and generates coverage report (target: 75%) pvm test --coverage=80.5 # .............. Runs all tests and generates coverage report (target: 80.5%) pvm test --tag=myTag #................... Runs helpers.tests.ps1 and list.tests.ps1 with Diagnostic verbosity and only runs tests with tag "myTag". COMMAND_BLOCK: pvm test [files = (files inside the tests/ directory)] [--coverage[=<number>]] [--verbosity=(None|Normal|Detailed|Diagnostic)] [--tag=<tag>] # Examples: pvm test # .............................. Runs all tests with Normal (default) verbosity. pvm test use install # .................. Runs only 'use.tests.ps1' and 'install.tests.ps1' files with Normal verbosity. pvm test --verbosity=Detailed # ......... Runs all tests with Detailed verbosity. pvm test --coverage # ................... Runs all tests and generates coverage report (target: 75%) pvm test --coverage=80.5 # .............. Runs all tests and generates coverage report (target: 80.5%) pvm test --tag=myTag #................... Runs helpers.tests.ps1 and list.tests.ps1 with Diagnostic verbosity and only runs tests with tag "myTag". - Windows 10/11 - PowerShell 5.1 or later - Configures necessary environment variables - Adds PVM to your system PATH - Creates backup of your current PATH configuration - Sets up the PHP version switching mechanism - Popular/common PHP settings (key-value pairs with enabled/disabled state) - Popular/common extensions (enabled/disabled state and type) - Metadata (name, description, creation date, PHP version) - Contains detailed error information when commands fail - Check this file first when troubleshooting installation or configuration issues - Automatic backup of your system's PATH variable created during setup - Used for system recovery if environment - Cached list of available PHP versions storage/data/available_versions.json - Cached list of available PHP extensions storage/data/available_extensions.json - Explore the full command list using pvm help - Install your first PHP version with pvm install <version> - Contribute or report issues on GitHub - Share your feedback and suggest features - 👉 If you find PVM helpful, consider giving it a star ⭐ on GitHub, an upvote PVM on ProductHunt here or leave a review here) — it really helps others discover the project and keeps development going.