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
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.
Set up a bin
directory right under /home/my-username
:
cd ~
mkdir bin
Move the composer.phar
(or any other of those nifty new PHP imps that are on the rise)
into the ~/bin
directory 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
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
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" "$@"
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
Getting composer to work globally inside Cygwin is a pain in the butt...
The solutions I have come up with:
Don't use it globally. If you are using the PHP CLI from a Windows installation, it won't recognize the Linux paths that Cygwin uses.
What I have done is put it in the base directory of all the projects I use composer with, and do ../composer.phar to run it.
It works fine this way, and it's almost globally available...
Download, and compile your own PHP binaries within Cygwin... Yea, kind of a overkill.
I solved the problem like this in a Cygwin/XAMPP setup:
Install composer.phar
to XAMPP's php
directory
Create an executable Bash script named composer
in XAMPP's php
directory:
#!/bin/bash
script_dir=$(cygpath -w $(dirname $0))
php "$script_dir/composer.phar" $@
It's important to use cygpath -w
to convert the path to a path in Windows form.
Make sure XAMPP's php
directory is accessible in Cygwin's $PATH
:
$ export PATH=$PATH:/cygdrive/i/dev/server/xampp/php
Now it's possible to call composer
from anywhere you like without problems:
$ composer -V
Composer version 264f433ca3f007d39568b3722b4bf418f58ba15b
How about this one?
alias composer='php c:\\your\\path\\to\\composer.phar'
source ~/.bashrc
Works for me using both Cygwin's native php.exe and XAMPP's Windows-specific one.
What I did (very simple):
composer
you will see something like Could not open input file: /c/route/to/your/composer/installation/bin
composer='composer.bat'
on your bash profile or bashrc or whateverI'm running Windows 8.1
I think what might work is to build a proxy instead:
Create a bash proxy as /usr/local/bin/composer with the following:
#!/bin/sh
c:/path/to/php c:/path/to/composer.phar $@
chmod +x /usr/local/bin/composer