I have already use WAMP 2.5 with PHP 5.5.12, and with Composer. The php is on:
C:\wamp\bin\php\php5.5.12
For new project, I need to use nginx and installed PHP 7. The php is on:
C:\nginx\php
Now, using GitBash MINGW32, I tried to install laravel 5.3 using Composer create-project
but it said
[InvalidArgumentException]
Could not find package laravel/laravel with version 5.3 in a version
installable using your PHP version 5.5.12.
I already put both C:\wamp\bin\php\php5.5.12
and C:\nginx\php
on Windows System PATH variable.
How do I change the PHP version used by Composer?
Three ways to do this, really.
Create an alias in
.bashrc
to always run composer with the corresponding versionSomething like
alias ncomposer=`/path/to/php /path/to/composer.phar `
Specify the path to PHP version inside
composer.phar
itselfThis is specified at the start of the file:
#!/path/to/php php
. Then composer should run withcomposer.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 :
cd ~/
to go to your home foldertouch .bash_profile
to create your new file..bash_profile
with your favorite editorIn 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 :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 :
Example : in the project that requires at least PHP 7.1.3
Using composer :
Using composer733 (the alias I created) :
It works, without having to change the environment variables