Version Switching
PHM installs multiple PHP versions side by side. There are two ways to switch between them.
Recommended: Symfony CLI + .php-version
Section titled “Recommended: Symfony CLI + .php-version”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.
- Install Symfony CLI via PHM:
phm install symfony- Create a
.php-versionfile in your project root:
echo "8.5" > .php-version- Use
symfony phpinstead ofphp:
symfony php -v# PHP 8.5.4 (cli) ...
symfony composer installsymfony console cache:clearSymfony CLI reads the .php-version file and automatically selects the correct PHP binary from PHM’s /opt/php/ directory.
Per-project workflow
Section titled “Per-project workflow”project-a/├── .php-version # Contains: 8.4├── composer.json└── src/
project-b/├── .php-version # Contains: 8.5├── composer.json└── src/cd project-asymfony php -v # PHP 8.4.19
cd ../project-bsymfony php -v # PHP 8.5.4Symfony local web server
Section titled “Symfony local web server”Symfony CLI includes a built-in web server that also respects .php-version:
# Start the server (uses PHP version from .php-version)symfony server:start -d
# Check which PHP version is being usedsymfony server:status
# View logssymfony server:log
# Stop the serversymfony server:stopThe Symfony server provides automatic HTTPS with locally-trusted certificates, HTTP/2 support, and handles .php-version seamlessly.
Alternative: phm use
Section titled “Alternative: phm use”For setting a system-wide default PHP version:
# Set PHP 8.5 as the global defaultphm use 8.5
# Verifyphp -vThis creates symlinks in /opt/php/bin/ pointing to the selected version. It affects all terminal sessions.
Comparison
Section titled “Comparison”| Feature | Symfony CLI + .php-version | phm use |
|---|---|---|
| Scope | Per-project | Global |
| Switching | Automatic (reads file) | Manual command |
| Team-friendly | Yes (commit .php-version) | No |
| Web server | Built-in (with HTTPS) | Requires separate setup |
| Recommended | Yes | For simple setups |