Search code examples
phpsymfonysymfony5

Running 2 Symfony projects with different php versions


I'm working on a Symfony (4.4) project with PHP version(7.1.30) and now I want to start a new Symfony (5.0/5.1) project.

But I could not do it because it wants at least PHP 7.2.5. (Windows 10 machine).

I have installed PHP 7.3.6 and added it to the PATH environment. But when I try to create the new Symfony project I get this error:

Your requirements could not be resolved to an installable set of packages.

Problem 1 - symfony/symfony v5.0.2 requires php ^7.2.5 -> your PHP version (7.1.30) does not satisfy that requirement. - symfony/symfony v5.0.1 requires php ^7.2.5 -> your PHP version (7.1.30) does not satisfy that requirement. - symfony/symfony v5.0.0 requires php ^7.2.5 -> your PHP version (7.1.30) does not satisfy that requirement. - Installation request for symfony/symfony ^5.0 -> satisfiable by symfony/symfony[v5.0.0, v5.0.1, v5.0.2].

Can you please advise how can I use 2 different PHP versions for the different projects?

(I can't upgrade the 'old' project because some extensions cannot work with 7.2.5)


Solution

  • You can select the php version for the project with

    echo 7.4.10 > .php-version
    

    When you create the .php-version for each project you can run the server as you run it usually and everything works fine

    Also, when I use 7.4.10 locally, I have to use my commands like this

    symfony php bin/console make:migration
    

    with symfony before php bin/console