Learn how to configure the PHP version used by the Symfony Binary in Windows.

In the last days, a friend of mine tried to create a new Symfony project using the Symfony binary in Windows, however he found some problems because there were more than a single PHP version installed on the computer and the default one was PHP 5.6 (which is unsupported for Symfony 5 at least). Using the Symfony binary in Windows you can easily list all of the recognized PHP versions using the following command (they will appear as long as the name of the binary is php and it's located in the PATH):

symfony local:php:list

This will output a table like the following one:

Symfony Binary used PHP Versions

In my case for this example, I'll be using 2 versions of PHP simultaneously in my PC, however PHP version 5.6.40 is the default one. You can switch the used PHP version of the Symfony binary in Windows in 2 different ways so I will explain each of them in this short article.

A. Specifying the PHP version with the .php-version file

Considering the installation or location path of the Symfony.exe file (the binary usually located at C:\Program Files\Symfony), you need to create a new empty file that contains the PHP version that you want to use (keeping in mind that you can use only the ones that are listed in the previously generated table). Create the .php-version file inside the same directory where the symfony.exe file is located and set as content the version of PHP that you want to use. In my case, the default PHP version in the system is 5.6.40, so I can specify to the binary that the version 8.0.12 should be used instead:

8.0.12

Save the changes of the file and restart your command prompt (launch a new one) and you will see now in the list that the used version will be the one specified in the .php-version file:

Symfony Binary custom PHP version

B. Switching Environment Variables Path Order

By default the used version is the first one that's available in the PATH. So, if you have multiple PHP installations in your computer and they're available in the PATH, you only need to change the order in the environment variables of Windows. Search for Environment variables in the windows search menu:

Environment Variables Windows

Then click on Environment variables:

Environment Variables Windows

As last step, search for the PATH environment variable and modify it. You will find your PHP installation directories there:

PHP Order in Path Windows

You only need to set as first (clicking Move Up and Move Down) the path of the PHP version that you want to use. Click on Ok, save the changes and restart your command prompt. The PHP environment variable should have now the version of the directory that appears as first on the list.

How to update the list of available PHP installations

You can update the list of the installed PHP instances in your system using the following instruction:

symfony local:php:refresh

Happy coding ❤️!


Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Become a more social person

Sponsors