Windows Command Line - Multiple PHP Versions

不想你离开。 提交于 2020-07-10 06:15:42

问题


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.

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" ??

Thanks!


回答1:


I am doing something like below.

ex. I have two php version , PHP 5.6 and PHP 7.3

I have wamp environment so I have done as below

so I have copied D:\wamp\bin\php\php7.3.6\php.exe to D:\wamp\bin\php\php7.3.6\php7.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.

now you need reopen the cmd and you can use command something like below

php56 -v
php7 -v

I hope this will help




回答2:


Its quite simple really.

Create yourself a batch file to add php to the path, place that file in one of the folders that is currently on your PATH so you can run it from anywhere. Then whenever you are in any folder that has CLI scripts in it run the batch file

Example batch file:

Lets call it PHPPATH.CMD

path=%path%;c:\wamp\bin\php\php5.4.11
php -v

Now if you want to use another version of the PHP CLI just change the batch file or if you are feeling clever make the batch file accept a paramter so you can specify the version of php you want on the path.




回答3:


If you are able to do so, just create aliases:

alias 'php56'='/Path/To/php5.6/bin/php'; alias 'php55'='/Path/To/php5.5/bin/php';

If not, create links in a seperate directory that point to the binaries.

php56 is a link to /Path/To/php5.6/bin/php

php55 is a link to /Path/To/php5.5/bin/php

put these into /Seperate/Path/ and add '/Seperate/Path/' to %PATH%

Hope this helps



来源:https://stackoverflow.com/questions/15617515/windows-command-line-multiple-php-versions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!