Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composer & Cygwin

Composer doesn't run correctly in Cygwin if you try to install it "globally".

Putting composer.phar into /usr/local/bin/composer, then trying to run it will result in the error:

Could not open input file: /usr/local/bin/composer 
like image 902
Populus Avatar asked Sep 05 '12 07:09

Populus


People also ask

What is composer and how it works?

Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

What is the latest version of composer?

To quickly install Composer in the current directory, run the following script in your terminal. To automate the installation, use the guide on installing Composer programmatically.

Where does composer get packages from?

Composer downloads directly from the source, e.g. Packagist only knows those source and tells your composer instance where to go. It does this by downloading a bunch of json files from Packagist.org that have all the infos.


1 Answers

Just tripped over the same problem and found a solution. Posting it here, just in case I'll ever have to look it up again.

  1. Set up a bin directory right under /home/my-username:

    cd ~ mkdir bin 
  2. Move the composer.phar (or any other of those nifty new PHP imps that are on the rise) into the ~/bindirectory and make sure to set it's execution bit:

    # Notice how I got rid of the superfluous `.phar` extension mv /path/to/composer.phar ~/bin/composer chmod +x ~/bin/composer 
  3. Tell cygwin to include your ~/bin directory in the search path:

    Open up the file ~/.bash_profile and uncomment the following paragraph ...

    # Set PATH so it includes user's private bin if it exists if [ -d "${HOME}/bin" ] ; then   PATH="${HOME}/bin:${PATH}" fi 
  4. Now, for the most important part:

    A wrapper script that helps Win's native PHP resolve Unix style paths (which is causing the problem after all as Windows doesn't know how to handle /cygdrive/... paths).

    cd ~/bin touch php chmod +x php 

    After editing the wrapper script ~/bin/php should read:

    #!/bin/bash  # e.g. php="/cygdrive/c/Program Files (x86)/php/php.exe" php="/path/to/php.exe"  for ((n=1; n <= $#; n++)); do     if [ -e "${!n}" ]; then         # Converts Unix style paths to Windows equivalents         path="$(cygpath --mixed ${!n} | xargs)"          case 1 in             $(( n == 1 )) )                 set -- "$path" "${@:$(($n+1))}";;             $(( n < $# )) )                 set -- "${@:1:$((n-1))}" "$path" ${@:$((n+1)):$#};;             *)                 set -- "${@:1:$(($#-1))}" "$path";;         esac     fi done  "$php" "$@" 
  5. Now restart your shell and it should correctly invoke the PHP interpreter whenever it stumbles upon a #!/usr/bin/env php shebang. Simply issue a:

    composer --help 
like image 141
aefxx Avatar answered Sep 24 '22 21:09

aefxx