PHP Version Manager is a comprehensive PowerShell tool that simplifies managing multiple PHP versions on Windows systems. It automatically detects all PHP installations (from WAMP, XAMPP, custom directories, and PATH) and creates convenient batch files for easy switching between versions.
- Auto-discovers all PHP installations on your system
- Creates batch files (
php72.bat,php80.bat, etc.) for each PHP version - Generates Composer wrappers (
cmp72.bat,cmp80.bat, etc.) for each PHP version - Manages active PHP version with simple commands
- Handles duplicate installations intelligently
- Downloads and installs new PHP versions from official Windows builds
- Download the
generate-php-bat-files.ps1script - Run the script as Administrator:
.\generate-php-bat-files.ps1- Verify installation by running:
php -v
php80 -v
cmp --version
cmp82 --version| Command | Description |
|---|---|
php72 |
Run PHP 7.2 |
php80 |
Run PHP 8.0 |
php81 |
Run PHP 8.1 |
php82 |
Run PHP 8.2 |
php83 |
Run PHP 8.3 |
php84 |
Run PHP 8.4 |
php85 |
Run PHP 8.5 |
php |
Run active PHP version |
| Command | Description |
|---|---|
cmp72 |
Run Composer with PHP 7.2 |
cmp80 |
Run Composer with PHP 8.0 |
cmp81 |
Run Composer with PHP 8.1 |
cmp82 |
Run Composer with PHP 8.2 |
cmp83 |
Run Composer with PHP 8.3 |
cmp84 |
Run Composer with PHP 8.4 |
cmp85 |
Run Composer with PHP 8.5 |
cmp |
Run Composer with active PHP |
# Run Laravel development server with PHP 8.2
php82 artisan serve
# Run Artisan commands with PHP 8.2
php82 artisan migrate
php82 artisan cache:clear
# Run Laravel with PHP 8.3
php83 artisan serve# Install dependencies with PHP 8.2
cmp82 install
# Update dependencies with PHP 8.3
cmp83 update
# Run Composer commands
cmp82 require laravel/sanctum
cmp84 require --dev phpunit/phpunit# Run tests with PHP 8.2
php82 vendor/bin/phpunit
# Run tests with PHP 8.3
php83 vendor/bin/phpunit# List all installed PHP versions
.\generate-php-bat-files.ps1
# Select option 1 to list versions
# Or use the interactive menu to switch
# Select option 3 from main menuWhen you run the script, you'll see an interactive menu:
1. List installed PHP versions
2. Install / download PHP
3. Switch active PHP
4. Show active PHP
5. Remove PHP
6. Verify phpXX / cmpXX / php / cmp
7. Rebuild wrappers
8. PATH manager
9. System information
10. Duplicate / configuration diagnostics
11. Exit
| Option | What It Does |
|---|---|
| 1. List installed PHP versions | Shows all PHP versions found on system |
| 2. Install / download PHP | Downloads and installs new PHP version |
| 3. Switch active PHP | Changes the active PHP version |
| 4. Show active PHP | Displays current active PHP version details |
| 5. Remove PHP | Uninstalls a PHP version |
| 6. Verify commands | Checks if wrappers are working correctly |
| 7. Rebuild wrappers | Regenerates all batch files |
| 8. PATH manager | Manages PATH environment variable |
| 9. System information | Shows system and PHP details |
| 10. Duplicate diagnostics | Finds and handles duplicate PHP installations |
| 11. Exit | Closes the manager |
C:\Users\YourUsername\.php-manager\
├── bin\ # Batch files directory
│ ├── php72.bat # PHP 7.2 wrapper
│ ├── php80.bat # PHP 8.0 wrapper
│ ├── php81.bat # PHP 8.1 wrapper
│ ├── php82.bat # PHP 8.2 wrapper
│ ├── php83.bat # PHP 8.3 wrapper
│ ├── php84.bat # PHP 8.4 wrapper
│ ├── php85.bat # PHP 8.5 wrapper
│ ├── cmp72.bat # Composer for PHP 7.2
│ ├── cmp80.bat # Composer for PHP 8.0
│ ├── cmp81.bat # Composer for PHP 8.1
│ ├── cmp82.bat # Composer for PHP 8.2
│ ├── cmp83.bat # Composer for PHP 8.3
│ ├── cmp84.bat # Composer for PHP 8.4
│ ├── cmp85.bat # Composer for PHP 8.5
│ ├── php.bat # Active PHP wrapper
│ ├── cmp.bat # Active Composer wrapper
│ └── get-active-php.ps1 # Helper script
├── versions\ # Installed PHP versions
│ ├── 7.2.34\ # PHP 7.2.34 installation
│ ├── 8.2.12\ # PHP 8.2.12 installation
│ └── ...
├── downloads\ # Downloaded PHP ZIP files
├── registry.json # PHP installations registry
└── active.json # Active PHP configuration
# Run the script
.\generate-php-bat-files.ps1
# Select option 2 (Install / download PHP)
# Enter version: 8.5.0
# Choose architecture: x64
# Choose Thread Safety: 1 (NTS) or 2 (TS)The script automatically detects duplicate PHP installations and provides options to:
- Keep only the canonical (best) version
- Select specific version to keep and move others
- Move all versions to manager directory
- Skip and keep all
The script automatically adds the bin directory to your User PATH, making all commands available globally.
# Test each PHP version
php72 -v
php80 -v
php81 -v
php82 -v
php83 -v
php84 -v
php85 -v
# Test active PHP
php -v# Test Composer with each PHP version
cmp72 --version
cmp80 --version
cmp81 --version
cmp82 --version
cmp83 --version
cmp84 --version
cmp85 --version
# Test active Composer
cmp --version# Create a new Laravel project with PHP 8.2
php82 composer create-project laravel/laravel my-project
cd my-project
# Run migrations with PHP 8.3
php83 artisan migrate
# Serve with PHP 8.4
php84 artisan serve- Cache Registry: The script caches PHP detection results for faster subsequent runs
- Active Version: Switching active PHP is instant (no file copying)
- Batch Files: Wrappers are lightweight and execute quickly
| Issue | Solution |
|---|---|
'php' is not recognized |
Run .\generate-php-bat-files.ps1 as Administrator |
Access Denied errors |
Run PowerShell as Administrator |
| Composer not found | Install Composer globally first |
| PHP version not switching | Check active.json file permissions |
| Duplicate installations detected | Use option 10 to resolve duplicates |
# Force rebuild wrappers
.\generate-php-bat-files.ps1
# Select option 7 (Rebuild wrappers)
# Reset PATH
# Select option 8 (PATH manager) → option 1 (Add to User PATH)
# Re-scan for PHP installations
# Select option 7 (Rebuild wrappers) - this triggers a fresh scan# .php-version file
8.2.12
# Or use wrapper commands in your workflow
php82 artisan serve
php82 artisan tinker
php82 artisan queue:work# Use specific PHP version for development
php84 -S localhost:8080
# Or with custom port
php83 -S localhost:8000- No More PATH Conflicts: Each PHP version has its own wrapper
- Easy Testing: Test code with different PHP versions instantly
- Project-Specific PHP: Run each project with its required PHP version
- Simple Commands: Just use
php82instead of full paths - Composer Integration: Run Composer with any PHP version
- WAMP/XAMPP Compatible: Works with existing WAMP/XAMPP installations
- Zero Configuration: Auto-detects all PHP installations
Feel free to contribute by:
- Reporting issues
- Suggesting features
- Improving documentation
- Testing with different PHP setups
This script is provided as-is for PHP development management.
- Create Alias: Add
alias phpm=".\generate-php-bat-files.ps1"to your PowerShell profile - Version Check: Always verify PHP version before deployment
- CI/CD Integration: Use wrapper commands in your CI/CD pipelines
- Multiple Projects: Use different PHP versions for different projects simultaneously
- Quick Switch: Change active PHP version in seconds
# Run PHP with specific configuration
php82 -c custom.ini script.php
# Run Composer with memory limit
cmp83 -d memory_limit=-1 install
# Debug with specific PHP version
php84 -r "echo phpinfo();"
# Run PHPUnit with specific PHP
php81 vendor/bin/phpunit --testsuite=FeatureHappy PHP Version Management! 🚀