So I have Gentoo box with three PHP versions installed (nevermind the reasons):
/usr/bin/php
->/usr/lib64/php5.4/bin/php
/usr/bin/php5.5
->/usr/lib64/php5.5/bin/php
/usr/bin/php5.6
->/usr/lib64/php5.4/bin/php
I want to install Laravel framework using composer:
$ composer create-project laravel/laravel --prefer-dist
This however throws an error because Laravel requires PHP > 5.5.9 and the default php
interpreter is 5.4.
So I issue another command:
$ /usr/bin/php5.6 /usr/bin/composer create-project laravel/laravel --prefer-dist
This takes me one step further, but then some post-install commands from Laravel's composer.json
comes into play, and installation crashes.
This is due to the fact, that composer.json
commands look like this:
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
As you can see, the "default" interpreter is used again!
Now, proper PHP files start with following shebang:
#!/usr/bin/env php
This is nice feature as PHP interpreter can be found under different locations on different systems.
Unfortunatelly, in this case env
command returns path to the first executable it finds in $PATH
environmental variable.
How could I possibly alter current session environment or what kind of trick to perform so for the execution of whole Laravel installation process php
command would invoke /usr/bin/php5.6
instead of /usr/bin/php
?
I don't want to change $PATH
variable or modify files like composer
, composer.json
or Laravel's CLI utility artisan
.
Edit: also assume that I want to do this from regular user account (i.e. with no root permissions).
GNU stow
– RavenousPHP_BIN
environment variable for example, or defaults to/usr/bin/php
else. (See also In Bash, when to alias, when to script, and when to write a function?) -- Also, once you have more than three versions installed, you're officially a hoarder. – Decreasingalias
: sadly this does not work. Perhaps becausealias
does not work whenphp
is invoked bycomposer
or by/usr/bin/env
. – Bronez