Search code examples
phpcomposer-phpphar

composer command not work - PHP Warning: Phar::mapPhar


I cannot run the composer command. I'm using windows cmd.

Inside C:\ProgramData\ComposerSetup\bin, I can do php composer.phar and it works.

But if do composer or composer.bat, I get this :

 PHP Warning:  Phar::mapPhar(/cygdrive/c/ProgramData/ComposerSetup/bin/c:\ProgramData\ComposerSetup\bin\composer.phar): failed to open stream: No such file or directory in /cygdrive/c/ProgramData/ComposerSetup/bin/c:\ProgramData\ComposerSetup\bin\composer.phar on line 23
PHP Fatal error:  Uncaught exception 'PharException' with message 'unable to open phar for reading "/cygdrive/c/ProgramData/ComposerSetup/bin/c:\ProgramData\ComposerSetup\bin\composer.phar"' in /cygdrive/c/ProgramData/ComposerSetup/bin/c:\ProgramData\ComposerSetup\bin\composer.phar:23
Stack trace:
#0 /cygdrive/c/ProgramData/ComposerSetup/bin/c:\ProgramData\ComposerSetup\bin\composer.phar(23): Phar::mapPhar('composer.phar')
#1 {main}
  thrown in /cygdrive/c/ProgramData/ComposerSetup/bin/c:\ProgramData\ComposerSetup\bin\composer.phar on line 23

What's wrong ?

I'm using the cygwin php in my path (cygwin/bin).

It works if I use a new php installation. But I want to keep "cygwin/bin" in my path.


Solution

  • I found it !

    Removing "c:\cygwin64\bin" in the path. Adding new php installation in path : "c:\php"

    Adding new system variable : "CYGWIN_HOME", with value c:\cygwin64.

    This way, using windows cmd, composer will use the php in the path ("c:\php").

    And using cygwin, composer will use the php in "cygwin\bin" (because of the CYGWIN_HOME variable).