Skip to content

Version Switching

PHM installs multiple PHP versions side by side. There are two ways to switch between them.

The recommended approach is to use Symfony CLI with a .php-version file in your project root. This gives you automatic, per-project PHP version switching.

  1. Install Symfony CLI via PHM:
Terminal window
phm install symfony
  1. Create a .php-version file in your project root:
Terminal window
echo "8.5" > .php-version
  1. Use symfony php instead of php:
Terminal window
symfony php -v
# PHP 8.5.4 (cli) ...
symfony composer install
symfony console cache:clear

Symfony CLI reads the .php-version file and automatically selects the correct PHP binary from PHM’s /opt/php/ directory.

project-a/
├── .php-version # Contains: 8.4
├── composer.json
└── src/
project-b/
├── .php-version # Contains: 8.5
├── composer.json
└── src/
Terminal window
cd project-a
symfony php -v # PHP 8.4.19
cd ../project-b
symfony php -v # PHP 8.5.4

Symfony CLI includes a built-in web server that also respects .php-version:

Terminal window
# Start the server (uses PHP version from .php-version)
symfony server:start -d
# Check which PHP version is being used
symfony server:status
# View logs
symfony server:log
# Stop the server
symfony server:stop

The Symfony server provides automatic HTTPS with locally-trusted certificates, HTTP/2 support, and handles .php-version seamlessly.

For setting a system-wide default PHP version:

Terminal window
# Set PHP 8.5 as the global default
phm use 8.5
# Verify
php -v

This creates symlinks in /opt/php/bin/ pointing to the selected version. It affects all terminal sessions.

FeatureSymfony CLI + .php-versionphm use
ScopePer-projectGlobal
SwitchingAutomatic (reads file)Manual command
Team-friendlyYes (commit .php-version)No
Web serverBuilt-in (with HTTPS)Requires separate setup
RecommendedYesFor simple setups