为一个命令使用不同的PHP版本CLI可执行文件 [英] Use different PHP version CLI executable for one command
问题描述
所以我有Gentoo框,安装了三个PHP版本(不明白的原因):
-
/ 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
我要安装 Laravel framework < a>使用作曲者:
$ composer create-project laravel / laravel --prefer-dist
然而,这会引发错误,因为Laravel需要PHP> 5.5.9和默认的 php
口译员是 5.4 。
所以我发出另一个命令:
$ /usr/bin/php5.6 / usr / bin / composer create - 项目laravel / laravel --prefer-dist
这需要我一步,来自Laravel的 composer.json
的-install命令发挥作用,安装崩溃。
这是因为事实, composer.json
命令如下所示:
install-cmd:[
php artisan clear-compiler,
php artisan optimization
],
如您所见,默认解释器将再次使用!
现在,正确的PHP文件以下列方式开始: :
#!/ usr / bin / env php
这是一个很好的功能,因为PHP解释器可以在不同的系统上的不同位置找到。
Unfortunatelly,在这种情况下, env
命令返回到 $ PATH
环境变量中找到的第一个可执行文件的路径
我如何改变当前的会话环境,或者执行整个Laravel安装过程执行什么样的技巧 php
命令将调用 /usr/bin/php5.6
而不是 / usr / bin / php
?
我不想更改 $ PATH
变量或修改文件,如 composer
, composer.json
或Laravel的CLI实用程序 artisan
。
编辑:还假设我想从常规用户帐户(即没有root用户权限)执行此操作。
也许你可以尝试修复环境!
$ php -v
或者,如果您不想修改shell会话的PATH,则只能对当前命令进行更改: p $ p
PHP 5.4.x(cli)...
$ set PATH =/ usr / lib64 / php5.6 / bin:$ PATH
$ php -v
PHP 5.6.x(cli)...
$ php -v
PHP 5.4.x(cli)...
$ env PATH =/ usr / lib64 / php5.6 / bin:$ PATHphp -v
PHP 5.6.x(cli)...
$ php -v
PHP 5.4.x(cli)...
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 likecomposer
,composer.json
or Laravel's CLI utilityartisan
.
Edit: also assume that I want to do this from regular user account (i.e. with no root permissions).
解决方案Maybe you can try to fix the environnement!
$ php -v PHP 5.4.x (cli) ... $ set PATH="/usr/lib64/php5.6/bin:$PATH" $ php -v PHP 5.6.x (cli) ...
Or, if you don't want to modify the PATH for your shell session, you can scope the change for the current command only:
$ php -v PHP 5.4.x (cli) ... $ env PATH="/usr/lib64/php5.6/bin:$PATH" php -v PHP 5.6.x (cli) ... $ php -v PHP 5.4.x (cli) ...
这篇关于为一个命令使用不同的PHP版本CLI可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!