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.
What is PVM ?
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.
Project Structure Overview
PVM follows a well-organized structure that separates concerns and maintains clean code architecture:
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
│ ├── helpers/ # 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
Key Features
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.
Prerequisites
- Windows 10/11 or Windows Server
- PowerShell 5.1 or later
Installation & Setup
Getting started with PVM has been significantly simplified with the new automated setup process:
Step 1: Clone the Repository
First, clone the PVM repository to your local machine:
git clone https://github.com/drissboumlik/pvm
cd pvm
Step 2: Automated Setup
Run the setup command to automatically configure PVM:
pvm setup
The setup process automatically:
- Configures necessary environment variables
- Adds PVM to your system PATH
- Creates backup of your current PATH configuration
- Sets up the PHP version switching mechanism
Command Reference
PVM provides a comprehensive set of commands for managing your PHP installations and configurations:
Getting Help
pvm help
Display all available commands and their descriptions, serving as your quick reference guide.
Checking Current Version
pvm current
Shows which PHP version is currently active on your system.
Listing PHP Versions
pvm list
Display all PHP versions currently installed on your system.
pvm list
View all PHP versions available for installation from your configured sources.
pvm list available
Installing PHP Versions
Basic Installation:
pvm install <version>
Install a specific PHP version. Replace <version>
with the desired version number (e.g., 7.4.33
or 8.2.0
).
Installation with Extensions:
pvm install <version> --xdebug --opcache
Install PHP with popular extensions enabled:
--xdebug
: Includes Xdebug for debugging--opcache
: Enables OPcache for improved performance
Uninstalling PHP Versions
pvm uninstall <version>
Remove a specific PHP version from your system cleanly, including all associated files and configurations.
Switching Between Versions
pvm use <version>
Switch your active PHP version to the specified version, updating all necessary environment variables automatically.
pvm use auto
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.
PHP Configuration Management
One of PVM's most powerful features is its ability to manage PHP configurations and extensions directly from the command line:
Extension Management
Enable Extensions:
pvm ini enable xdebug opcache
Enable multiple extensions simultaneously. PVM will modify the appropriate php.ini file and ensure the extensions are properly loaded.
Disable Extensions:
pvm ini disable xdebug opcache
Disable extensions when they're no longer needed, improving PHP performance.
PHP Settings Management
Set Configuration Values:
pvm ini set memory_limit=512M max_file_uploads=20
Modify multiple PHP settings in one command. This is particularly useful for adjusting settings for different development scenarios.
Get Configuration Values:
pvm ini get memory_limit max_file_uploads
Retrieve current values of specific PHP settings to verify your configuration.
Restore Configuration:
pvm ini restore
Restore php.ini settings from backup, useful when you need to revert changes or start fresh.
Running Tests
Run tests against the PowerShell scripts in the repo — especially useful for contributors verifying changes before submitting a pull request:
Requirements
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:
Install-Module -Name Pester -Force -SkipPublisherCheck
💡 If prompted to trust the repository, type Y and press Enter.
You can verify the installation with:
Get-Module -ListAvailable Pester
Run the tests
pvm test [files = (files inside the tests/ directory)] [verbosity = (None|Normal|Detailed|Diagnostic)]
# Examples:
pvm test # Runs all tests with Normal verbosity.
pvm test use install # Runs only use.tests.ps1 and install.tests.ps1 with Normal verbosity.
pvm test Detailed # Runs all tests with Detailed verbosity.
pvm test helpers list Diagnostic # Runs helpers.tests.ps1 and list.tests.ps1 with Diagnostic verbosity.
Logging and Storage System
PVM maintains essential files for troubleshooting and performance:
Key Files
Error Logging: storage/logs/error.log
- Contains detailed error information when commands fail
- Check this file first when troubleshooting installation or configuration issues
PATH Backup: storage/logs/path.bak.log
- Automatic backup of your system's PATH variable created during setup
- Used for system recovery if environment variables need restoration
Available Versions Cache: storage/data/available_versions.json
- Cached list of available PHP versions for faster performance
Quick Troubleshooting
# Check for errors
type storage\logs\error.log
Final Thoughts
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.
What's Next?
- 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 — it really helps others discover the project and keeps development going.
PVM is open-source and community-driven — your input can help shape its future.