yiienvironment-variableswampyii-migrations

How to switch PHP versions in environment variables?


Since I'm required to work on both PHP5.x and PHP7.x projects in Yii framework, I've installed WAMP.

I've also set up my environment variables to link to both paths containing php.exe and for just working with the projects, that's just fine.

However, whenever I need to run migrations, there's a problem: if PHP7 path is defined first, PHP5 migrations won't run and if PHP5 path is listed first, PHP7 migrations won't work anymore.

Error message for PHP5:

'yii' is not recognized as an internal or external command, operable program or batch file.

Error message for PHP7:

Parse error: syntax error, unexpected '?' in C:\wamp64\www\project\vendor\phpunit\phpunit\src\Framework\TestCase.php on line 822

Is there a clean way to be able to define which PHP version you wish to use when running migrations, without having to reconfigure your environment variables again and again?


Solution

  • Thank you @RiggsFolly for your help. Based on the link you provided, I compiled a handy solution:

    I started off by creating 2 new files in C:\Windows\System32 (since this path is already included in the environment variables):

    startphp5.cmd and startphp7.cmd.

    startphp5.cmd contains just this (start7.php is obviously almost the same):

    PATH=%PATH%;C:\wamp64\bin\php\php5.6.31
    php -v
    

    Before running my migrations in my command prompt, all I have to do now is run either "startphp5" or "startphp7".