Change PHP version used by Composer on Windows
Three ways to do this, really.
Create an alias in .bashrc
to always run composer with the corresponding version
Something like alias ncomposer=`/path/to/php /path/to/composer.phar `
Specify the path to PHP version inside composer.phar
itself
This is specified at the start of the file: #!/path/to/php php
. Then composer should run with composer.phar
NB! The line will disappear upon self-update, so it's not a reliable solution.
Move up the path with the newest PHP version
If you place C:\nginx\php
first, it should be used by default when using composer.
Hope this helps!
Although this question was solved, the answer didn't help me. I will explain how I managed to make composer to work in a version of PHP different from the one which is installed by default on my OS (PHP 7.1.1) as well as in my environment variables (these will not be changed !). Note that I'm using Xampp, but the principle remains the same for Wamp.
Starting from this answer :
- Start up Git Bash
- Type
cd ~/
to go to your home folder - Type
touch .bash_profile
to create your new file. - Edit
.bash_profile
with your favorite editor
In my case I have a folder named
php733
inside xampp folder which corresponds to PHP 7.3.3. This is this other answer that helped me in creating the alias :alias composer733='/c/[xampp folder]/php733/php.exe /c/ProgramData/ComposerSetup/bin/composer.phar '
Then, type
. .bash_profile
to reload.bash_profile
and update any functions you add. Notice the space between the two dots !
Finally, type this command in Git Bash :
composer733 [whatever you wan]
Example : in the project that requires at least PHP 7.1.3
Using composer :
$ composer update This package requires php ^7.1.3 but your HHVM version does not satisfy that requirement.
Using composer733 (the alias I created) :
$ composer733 update Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 98 installs, 0 updates, 0 removals - Installing [...] (v1.11.0): Loading from cache
It works, without having to change the environment variables