It’s simple, run:

symfony local:php:list

To check which versions are available, it will highlight the default version, like this:

┌─────────┬────────────┬───────────┬────────────────┬─────────┬─────────┬─────────┐
│ Version │ Directory  │  PHP CLI  │    PHP FPM     │ PHP CGI │ Server  │ System? │
├─────────┼────────────┼───────────┼────────────────┼─────────┼─────────┼─────────┤
│ 7.3.29  │ /usr       │ bin/php   │ sbin/php-fpm   │         │ PHP FPM │ *       │
│ 7.4.25  │ /opt/local │ bin/php74 │ sbin/php-fpm74 │         │ PHP FPM │         │
│ 8.0.12  │ /opt/local │ bin/php80 │                │         │ PHP CLI │         │
└─────────┴────────────┴───────────┴────────────────┴─────────┴─────────┴─────────┘

Now say you want to switch to PHP 7.4.*, simply run:

echo 7.4 > ~/.php-version

Now run Symfony CLI again to check if it switched the default version:

symfony local:php:list

And we can see it switched the default version:

┌─────────┬────────────┬───────────┬────────────────┬─────────┬─────────┬─────────┐
│ Version │ Directory  │  PHP CLI  │    PHP FPM     │ PHP CGI │ Server  │ System? │
├─────────┼────────────┼───────────┼────────────────┼─────────┼─────────┼─────────┤
│ 7.3.29  │ /usr       │ bin/php   │ sbin/php-fpm   │         │ PHP FPM │ *       │
│ 7.4.25  │ /opt/local │ bin/php74 │ sbin/php-fpm74 │         │ PHP FPM │         │
│ 8.0.12  │ /opt/local │ bin/php80 │                │         │ PHP CLI │         │
└─────────┴────────────┴───────────┴────────────────┴─────────┴─────────┴─────────┘

You can also create the .php-version file in a project directory, to change the PHP version per project.

To undo or change, simply delete or overwrite the .php-version file.

That’s all there is to it!

Did this help you out? Consider [donating a coffee] to keep my blog running!