Search code examples
phpcomposer-phpphpstorm

Unable to add command line tool support for the composer in Phpstorm


I'm using PHPStorm on Windows 10, WAMP server for php.exe and I've installed composer using ComposerSetup.exe for windows. I'm trying to add command line tool support for the composer in Phpstorm, but it fails and gives this error.

Problem Failed to parse output as XML: Error on line 2: Content is not allowed in prolog. Command php.exe C:\ProgramData\ComposerSetup\bin\composer list --xml Output

dir=$(d=$(dirname "$0"); cd "$d" && pwd)

# see if we are running in cygwin by checking for cygpath program
if command -v 'cygpath' >/dev/null 2>&1; then

    # cygwin paths start with /cygdrive/ which will break windows PHP,
    # so we need to translate the dir path to windows format. However
    # we could be using cygwin PHP which does not require this, so we
    # test if the path to PHP starts with /cygdrive/ rather than /usr/bin.
    if [[ $(which php) == /cygdrive/* ]]; then
        dir=$(cygpath -m $dir);
    fi
fi

dir=$(echo $dir | sed 's/ /\ /g')
php "${dir}/composer.phar" $*

Solution

  • PHPStorm should know about the locally installed PHP, and all it needs is the composer.phar file that contains the PHP source code of Composer.

    What you have given PHPStorm looks like a Windows batch file that detects some aspects of being called in Windows shells (like CMD vs. Cygwin), and THEN calls PHP with the path of composer.phar. This is no PHP source code that you could directly give to PHP, like PHPStorm does.

    Only configure the path of the phar file in PHPStorm, not that batch file.

    Alternatively, you can simply add Composer via the PHPStorm GUI - it should ask you to provide Composer if it isn't known, and a download possibility should be offered.

    There is an extensive help text available at their website just by googling "phpstorm install composer": https://www.jetbrains.com/phpstorm/help/using-composer-dependency-manager.html