DEV Community

Cover image for PVM - PHP Version Manager for Windows
Driss
Driss

Posted on

PVM - PHP Version Manager for Windows

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
β”‚   β”œβ”€β”€ 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

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
  • 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
Enter fullscreen mode Exit fullscreen mode

Step 2: Automated Setup

Run the setup command to automatically configure PVM:

pvm setup
Enter fullscreen mode Exit fullscreen mode

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

Display all available commands and their descriptions, serving as your quick reference guide.

pvm help
Enter fullscreen mode Exit fullscreen mode

Display help for a specific command with description, usage and examples

pvm help <command> # Example : pvm help use
Enter fullscreen mode Exit fullscreen mode

Display information about the environment

Display information about the current PHP (version, path, extensions, settings)

pvm info
pvm ini info
Enter fullscreen mode Exit fullscreen mode

Display information about the current PHP extensions

pvm info extensions # pvm ini info extensions
Enter fullscreen mode Exit fullscreen mode

Display information about the current PHP settings

pvm info settings # pvm ini info settings
Enter fullscreen mode Exit fullscreen mode

Display information about the current PHP (version, path, extensions, settings) with specific in their name

pvm info --search=<term> # pvm ini info --search=<term>
# Example : pvm info --search=cache
Enter fullscreen mode Exit fullscreen mode

Checking Current Version

Shows which PHP version is currently active on your system.

pvm current
Enter fullscreen mode Exit fullscreen mode

Listing PHP Versions

Display all PHP versions currently installed on your system.

pvm list # pvm ls
Enter fullscreen mode Exit fullscreen mode

List installed versions with specific version in the name

pvm list --search=<version>
# Example: pvm list --search=8.2
Enter fullscreen mode Exit fullscreen mode

View all PHP versions available for installation from your configured sources.

pvm list available # pvm ls available
Enter fullscreen mode Exit fullscreen mode

List available versions with specific version in the name

pvm list available --search=<version>
# Example: pvm list available --search=8.2
Enter fullscreen mode Exit fullscreen mode

Installing PHP Versions

Basic Installation:

pvm install <version> # pvm i <version>
# Example: pvm install 8.4 / pvm i 8.4
Enter fullscreen mode Exit fullscreen mode

Install a specific PHP version. Replace <version> with the desired version number (e.g., 7.4.33 or 8.2.0).

pvm install auto # pvm i auto
# Install the php version specified on your project.
Enter fullscreen mode Exit fullscreen mode

Uninstalling PHP Versions

pvm uninstall <version> # pvm rm <version>
# Example: pvm uninstall 8.4 # pvm rm 8.4
Enter fullscreen mode Exit fullscreen mode

Remove a specific PHP version from your system cleanly, including all associated files and configurations.

Switching Between Versions

pvm use <version> # Example: pvm use 8.4
Enter fullscreen mode Exit fullscreen mode

Switch your active PHP version to the specified version, updating all necessary environment variables automatically.

pvm use auto
Enter fullscreen mode Exit fullscreen mode

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

Check extensions status:

pvm ini status <extension> # Example: pvm ini status xdebug opcache
Enter fullscreen mode Exit fullscreen mode

Enable Extensions:

pvm ini enable xdebug opcache # Example: pvm ini enable xdebug opcache
Enter fullscreen mode Exit fullscreen mode

Disable Extensions:

pvm ini disable xdebug opcache # Example: pvm ini disable xdebug opcache
Enter fullscreen mode Exit fullscreen mode

PHP Settings Management

Set Configuration Values and change the status:

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

Get Configuration Values:

pvm ini get <setting>
# Example: pvm ini get memory_limit max_file_uploads
Enter fullscreen mode Exit fullscreen mode

Install extensions from remote source

pvm ini install <extension>
# Example: pvm ini install opcache
Enter fullscreen mode Exit fullscreen mode

List installed extensions

pvm ini list
Enter fullscreen mode Exit fullscreen mode

List available extensions from remote source

pvm ini list available
Enter fullscreen mode Exit fullscreen mode

List installed extensions with 'zip' in their name

pvm ini list --search=<extension>
# Example: pvm ini list --search=zip
Enter fullscreen mode Exit fullscreen mode

List available extensions with 'zip' in their name

pvm ini list available --search=<extension>
# Example: pvm ini list available --search=zip
Enter fullscreen mode Exit fullscreen mode

Restore Configuration:

pvm ini restore
Enter fullscreen mode Exit fullscreen mode

Restore php.ini settings from backup, useful when you need to revert changes or start fresh.

Check Logs:

pvm log --pageSize=[number] # Default value is 5
Enter fullscreen mode Exit fullscreen mode

This one will help you check the log file in a readable way, with pagination.

Manage PHP Configuration Profiles

Save, load, and share PHP settings and extensions using JSON profiles:

# 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

Profile Structure: Profiles are stored as JSON files in storage/data/profiles/ and contain:

  • 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)

Note: Only popular/common settings and extensions are saved in profiles. This keeps profiles focused and manageable.

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
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ If prompted to trust the repository, type Y and press Enter.

You can verify the installation with:

Get-Module -ListAvailable Pester
Enter fullscreen mode Exit fullscreen mode

Run the tests

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

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 for faster performance
:

  • Cached list of available PHP versions storage/data/available_versions.json
  • Cached list of available PHP extensions storage/data/available_extensions.json

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, an upvote PVM on ProductHunt here or leave a review here) β€” it really helps others discover the project and keeps development going.

Top comments (0)