1

How to install two composer in one windows system? (how to use difference composer in one windows system)

hakre
  • 193,403
  • 52
  • 435
  • 836
Ali Salehi
  • 23
  • 1
  • 8
  • 1
    Does this answer your question? [keep composer 1 & 2 both in same machine](https://stackoverflow.com/questions/65273012/keep-composer-1-2-both-in-same-machine) – hakre Jan 27 '23 at 18:04
  • What have you tried so far? Where are you stuck? Is there any good reason to use multiple Composer versions? – Nico Haase Jan 29 '23 at 16:19
  • hi @NicoHaase . If you want the truth, I wanted to handle the dependencies of several projects with different versions of PHP with Composer, and I don't need to change the PHP path in `env variables` every time for each project. But until now, I could not install another version of PHP on my `Composer1` ! If it is not possible to install another version of PHP on `Composer1`, then my work is useless! Do you have a solution to install another version of Php on the second composer? – Ali Salehi Jan 31 '23 at 16:31
  • Please add all clarification to your question by editing it. Usually, you can run Composer with any PHP version, it doesn't have to match the one your application uses – Nico Haase Feb 01 '23 at 07:52
  • @NicoHaase Does composer version2.5.1 support php7.2.5 ?!!!! – Ali Salehi Feb 01 '23 at 08:10
  • See https://getcomposer.org/doc/00-intro.md: "Composer in its latest version requires PHP 7.2.5 to run"; the current latest version is indeed 2.5.1 and I see no problem in using that on PHP 7.2.5. Otherwise, feel free to use v2.2 which even works with PHP 5.3.2 – Nico Haase Feb 01 '23 at 08:28

2 Answers2

1

for windows do the following steps:

  • one -> (create composer1 directory in C:\composer_path)

  • two -> (copy three file in composer directory to composer1 directory)

  • three -> (set path composer1 to environment variable)

  • four -> (run composer1 self-update --1 in cmd) because Convert to version 1.0.0

  • five -> (test versions composer)

and Done! ^_^

you can see two version of composer installed in one windows system.

Ali Salehi
  • 23
  • 1
  • 8
  • Congrats. Here a tip: Instead of 1.10.x use 2.2.x (or at least try with your new great setup). It's LTS and much faster (most of composer 1 plugins you don't need any longer with it, too, so you can easily get rid of them, too). – hakre Jan 28 '23 at 15:49
  • "this version latest version of support to php 7.2.5" - what do you mean by this? Composer 2.5.1 still supports PHP 7.2.5 – Nico Haase Feb 01 '23 at 08:29
0

If you're using the windows installer only, IIRC you can't as it ships with the precondition to install under the canonical composer name.

However if you download the phar file, you just need to use the phar file of the version you would like to execute. This works independently to using the windows installer - both with and without it.

This has also the benefit that you can specify the PHP executable you would like to run composer.phar with.

c:\> c:\my\php.exe c:\my\composer-2.2.10.phar --version

This is basically what the Composer manual means where-ever it writes php composer.phar ....

You replace php with the PHP executable you would like to use and composer.phar with the composer phar you would like to use.

The windows setup installer is just installing the latest with the PHP version on your system under the canonical name composer. But instead you can create your own composer.bat.

You can then also create two such files for the different versions, e.g. composer-blue.bat and composer-red.bat.

This technique should be compatible to have next to composer with the windows setup installer, so you can use it to install one version you manage with the setup and zero up to N versions you manage yourself with the phar files.

hakre
  • 193,403
  • 52
  • 435
  • 836
  • tnks for answer. but What should I do to solve this problem? – Ali Salehi Jan 28 '23 at 14:57
  • What about downloading the composer phar and then run it with the PHP command, e.g. `php composer.phar --version` from the directory where you downloaded it to see if you can get it running? Sounds like a good idea? – hakre Jan 28 '23 at 14:59
  • 1
    tanks @hakre . I resolved. ^_^ – Ali Salehi Jan 28 '23 at 15:45