Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Command Line - Multiple PHP Versions

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!

like image 769
Mike Avatar asked Mar 25 '13 14:03

Mike


People also ask

How do I run multiple PHP versions?

Add a PHP Repository So you'll need to add the PHP repository in your system to install the multiple PHP versions. Once the repository is up-to-date, you can proceed to install multiple PHP versions.

Can I have two PHP versions?

For example, you can have PHP 5.4 for the site in public_html and then use PHP 5.2 in a subdirectory. You can use any combination of other PHP versions in any directory on the account.

Can I run several version of PHP at the same time?

Yes we can run several versions of php. To do that we must have to check the INSTALL file, if it is included in PHP source distribution.


1 Answers

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.

enter image description here

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

php56 -v
php7 -v

You can also run command refreshenv to reload environment variables in opened cmd.

If you want change default php version, you can move paths as below.

ex if you want php 7.0.23 as default instead of php 7.3.6

see screenshot for exampleenter image description here

In above screenshot I have move php 7.0.23 above the all other php verions (php 7.3.6 and php 5.6.31).

I hope this will help.

like image 76
Rohit Ramani Avatar answered Oct 01 '22 08:10

Rohit Ramani