Windows命令行-多个PHP版本 [英] Windows Command Line - Multiple PHP Versions
问题描述
我当前正在运行具有多个PHP版本(5.3.8、5.4.3)的Wampserver.Wampserver可以轻松地让您在要使用Apache的php版本之间来回切换.但是,我在处理CLI的多个版本时遇到了麻烦.我有需要命令行的项目,但是有些与php5.4兼容,而有些则不行.
I am currently running Wampserver with multiple PHP versions (5.3.8, 5.4.3). Wampserver easily allows you to switch back and forth between the php version you want apache to use. However, I'm having trouble dealing with multiple versions from the CLI. I have projects that require the command line, but some are compatible with php5.4, while some are not.
有没有一种方法可以在Windows中创建某种别名",从而允许我在命令行上指定要使用的PHP版本.IE:"php54 cache:clear","php53 cache:clear"??
Is there a way to create some type of "alias" in Windows that allows me to specify which version of PHP to use on the command line .. I.E: "php54 cache:clear", "php53 cache:clear" ??
谢谢!
推荐答案
我正在执行以下操作.
例如我有两个php版本,PHP 5.6和PHP 7.3
ex. I have two php version , PHP 5.6 and PHP 7.3
我有潮湿的环境,所以我做了如下操作
I have wamp environment so I have done as below
所以我已经将D:\ wamp \ bin \ php \ php7.3.6 \ php.exe复制到D:\ wamp \ bin \ php \ php7.3.6 \ php7.exe
so I have copied D:\wamp\bin\php\php7.3.6\php.exe to D:\wamp\bin\php\php7.3.6\php7.exe
我已经将D:\ wamp \ bin \ php \ php5.6 \ php.exe复制到D:\ wamp \ bin \ php \ php5.6 \ php56.exe
and I have copied D:\wamp\bin\php\php5.6\php.exe to D:\wamp\bin\php\php5.6\php56.exe
然后我将它们都添加到如下所示的环境变量路径中.
Then I have added both to environment variable path like below.
现在您需要重新打开cmd,然后可以使用以下命令
now you need reopen the cmd and you can use command something like below
php56 -v
php7 -v
您还可以运行命令 refreshenv 以在打开的cmd中重新加载环境变量.
You can also run command refreshenv to reload environment variables in opened cmd.
如果要更改默认的php版本,则可以按以下方式移动路径.
If you want change default php version, you can move paths as below.
ex,如果您希望将php 7.0.23设置为默认值而不是php 7.3.6
ex if you want php 7.0.23 as default instead of php 7.3.6
例如,请参见屏幕截图
see screenshot for example
我希望这会有所帮助
这篇关于Windows命令行-多个PHP版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!