Composer & Cygwin - 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

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 ~/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
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

How about this one?
In ~/.bashrc, add: alias composer='php c:\\your\\path\\to\\composer.phar'
Restart cygwin or reload the bashrc by running source ~/.bashrc
Works for me using both Cygwin's native php.exe and XAMPP's Windows-specific one.

I think what might work is to build a proxy instead:
Put composer.phar in /usr/local/bin/composer.phar
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

Try this:
Install Cygwin PHP and use it to run composer in Cygwin.
You can choose one of two ways to work fine with PHP+Composer in Cygwin:
Install Cygwin PHP and install composer.phar in Cygwin.
Install Windows PHP and install Winodows Composer, then call then from Cygwin. (Windows XAMMP+Composer with alias in cmd)
Your problem is caused by that Cygwin Composer is ruining by Windows PHP on Cygwin, so it can not recognize the file path.
After install Cygwin PHP, the composer will integrates with Cygwin PHP then fit to Cygwin's filepath.
Cygwin PHP extensions for composer usage:
php
php-json
php-mbstring
php-phar
php-zip
php-posix
You can install other PHP extension when composer's package is needed such as php-xmlwriter, php-tokenizer, php-ctype.
Installation commands guide:
If you have already installed apt-cyg, there are installation command above:
apt-cyg install php php-json php-mbstring php-phar php-zip php-posix
apt-cyg install php-xmlwriter php-tokenizer php-ctype
Then install Composer via Cygwin PHP:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
chmod +x ./composer.phar
mv ./composer.phar /usr/bin/composer
composer -v
Conclusion
I recommend using Windows PHP + Windows Composer, and call then in Cygwin, it because the Cygwin PHP is not much stable than Windows PHP.

I had the same problem. After reading the final instruction from composer installer, it says that the $PATH variable should be reloaded. I rebooted my computer and then linked the Composer bin to /usr/local/bin.
First locate the composer bin :
/cygdrive/c/ProgramData/ComposerSetup/bin/composer
Then according to Seldaek answer, after trying a non-working symlink, I did :
nano /usr/local/bin/composer
#!/bin/sh
/cygdrive/c/ProgramData/ComposerSetup/bin/composer $#
chmod +x /usr/local/bin/composer
And it's working.

What I did (very simple):
Install Composer normally with the Windows installer
Open a Cygwin console an type composer you will see something like Could not open input file: /c/route/to/your/composer/installation/bin
Create an alias composer='composer.bat' on your bash profile or bashrc or whatever
Done
I'm running Windows 8.1

I was having this issue. Most of the responses were over my head but I fixed it with no problems.
Step 1) Reinstall Composer globally as per https://getcomposer.org/download/
Step 2) Leave it alone. All the special stuff you want to do, don't do that.
Step 3) Download the latest setup-xxx.exe from https://cygwin.com/
Step 4) Click it with your mouse.
NOTE: During step 5 you will feel a sudden urge to read instructions, browse the web for info and start checking little boxes on the menu. Don't do that.
Step 5) Click 'next' until it stops asking. It will look at your existing
settings, fix things up and add any missing dependencies.
This worked for me.

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

I fixed it by adding a /usr/local/bin/composer file:
nano /usr/local/bin/composer
with the following content:
#!/bin/bash
/cygdrive/c/wamp/bin/php/php5.4.3/php "C:\wamp\bin\php\php5.4.3\composer"
Basically, you have to call PHP with a Windows style path, not a cygwin path.

The easiest way is to install composer using the Windows installer from their website and then copy the two files 'composer' and 'composer.phar' from "C:\ProgramData\Composer" into a directory which is in the PATH variable. E.g. you could copy the files into the /bin/ directory of cygwin. Afterwards you can again uninstall the "Windows version" of composer.
Update! This is what I did:
Install PHP and needed modules from the Cygwin Ports project
Download the latest composer snapshot
Rename 'composer.phar' to 'composer' and save it to /usr/local/bin
Open /bin/dash.exe and run '/usr/bin/rebaseall'
Also if 4. gives you an error, composer should run now

I suggest you use babun, it is based cygwin, but you can install package by pact, you can do this:
pact install php php-json php-phar
php -r "readfile('https://getcomposer.org/installer');" | php
then enjoy yourself.

I was having trouble getting Composer to work in Cygwin and none of the solutions above were resolving my problem. Eventually I stumbled across this comment in the Composer github bugs discussion:
Yeah TBH using php from cygwin isn't a great idea, cygwin is just too different an environment. Too many hacks that create failures.. In any case closing here as there isn't much we can do I'm afraid :)
I don't know precisely where composer/Cygwin/php was tripping up, but, broadly, my problem was that I had two conflicting installations of PHP in environmental variables, one from an installation of WAMP, and another installed with Cygwin. The Cygwin PHP installation seemed to be struggling with some sort of path issue. I removed it, using only the WAMP PHP, and composer ran in Cygwin just fine.

Related

OpenShift oc command line with Cygwin

I'm running Cygwin 64bit but can't seem to get OpenShift oc command line to work
I downloaded oc.tar.gz ( from here https://mirror.openshift.com/pub/openshift-v3/clients/3.6.173.0.5/linux/oc.tar.gz ), unzipped it and placed it in my path in /usr/bin
When I try to run: oc login I get the following.
-bash: /usr/bin/oc: cannot execute binary file: Exec format error
Do I need to somehow 'install' the executable ?
Any help would be much appreciated.
In addition to #Graham Dumpleton's answer:
open cygwin and check for directory /usr/local/bin
mkdir -p local/bin
$ cd /usr/local/bin
if it does not exists:
$ mkdir -p local/bin
finally extract the windows package:
$ cp /cygdrive/c/Users/me/Downloads/oc-3.5.5.31.24-windows.zip /usr/local/bin/
unzip oc-3.5.5.31.24-windows.zip
$ oc version
oc v3.5.5.31.24
kubernetes v1.5.2+43a9be4
features: Basic-Auth
Use the Windows binary from the following page:
https://github.com/openshift/origin/releases
From project homepage
https://www.cygwin.com/
Cygwin is not:
a way to run native Linux apps on Windows. You must rebuild your
application from source if you want it to run on Windows.
a way to magically make native Windows apps aware of UNIX®
functionality like signals, ptys, etc. Again, you need to build your
apps from source if you want to take advantage of Cygwin
functionality.

how to fix $PATH in Virtual Box Ubuntu 14.04 after npm global install

I've been trying to install npm globally in virtual box with ubuntu 14.04 and Apache 2.4 with various problems with Laravel 5.1
Reading through the docs on npm adn following through these instructions https://docs.npmjs.com/getting-started/fixing-npm-permissions I know I have completed wrecked my $PATH
Previously when I ran echo $PATH I got something like this;
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games
Now when I echo $PATH I get the following;
/usr/local/bin:/bin
I have managed to stuff everything up on my Laravel install, composer no longer works, php artisan no longer works - am just wondering if anyone is able to help me get back to where I was...
For the novices who may be struggling with this, I got the path, composer, artisan and Laravel functioning by first, replacing the .bashrc with a non corrupt one in terminal from the /etc/skel directory (in local indicated by $)
$cp /etc/skel/.bashrc ~/
Commit changes with
$source ~/.bashrc
Then used the following to export /usr/bin to my PATH - the error for anything attempted in terminal was "The command could not be located because '/usr/bin' is not included in the PATH"
$export PATH="/usr/bin:$PATH"
To permanently commit the changes
$sudo nano /etc/environment
Check the file contains the following
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
CTRL & X to save and Y

sqlplus: error while loading shared libraries: libsqlplus.so: cannot open shared object file: No such file or directory

Please suggest a solution for solving this issue?? While giving the command:
sqlplus /nolog
the error that occurred:
sqlplus: error while loading shared libraries:
libsqlplus.so: cannot open shared object file: No such file or directory
The minimum configuration to properly run sqlplus from the shell is to set ORACLE_HOME and LD_LIBRARY_PATH. For ease of use, you might want to set the PATH accordingly too.
Assuming you have unzipped the required archives in /opt/oracle/instantclient_11_1:
$ export ORACLE_HOME=/opt/oracle/instantclient_11_1
$ export LD_LIBRARY_PATH="$ORACLE_HOME"
$ export PATH="$ORACLE_HOME:$PATH"
$ sqlplus
SQL*Plus: Release 11.1.0.7.0 - Production on Wed Dec 31 14:06:06 2014
...
sudo sh -c "echo /usr/lib/oracle/12.2/client64/lib > /etc/ld.so.conf.d/oracle-instantclient.conf";sudo ldconfig
from https://help.ubuntu.com/community/Oracle%20Instant%20Client
I did solve this error by setting
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib:$ORACLE_HOME
yes, not only $ORACLE_HOME/lib but $ORACLE_HOME too.
You should already have all needed variables in /etc/profile.d/oracle.sh. Make sure you source it:
$ source /etc/profile.d/oracle.sh
The file's content looks like:
ORACLE_HOME=/usr/lib/oracle/11.2/client64
PATH=$ORACLE_HOME/bin:$PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib
export ORACLE_HOME
export LD_LIBRARY_PATH
export PATH
If you don't have it, create it and source it.
I know it's an old thread, but I got into this once again with Oracle 12c and LD_LIBRARY_PATH has been set correctly.
I have used strace to see what exactly it was looking for and why it failed:
strace sqlplus /nolog
sqlplus tries to load this lib from different dirs, some didn't exist in my install. Then it tried the one I already had on my LD_LIBRARY_PATH:
open("/oracle/product/12.1.0/db_1/lib/libsqlplus.so", O_RDONLY) = -1
EACCES (Permission denied)
So in my case the lib had 740 permissions, and since my user wasn't an owner or didn't have oracle group assigned I couldn't read it. So simple chmod +r helped.
On Ubuntu Server 20.04 and using instant client version 19.10.0.0, I used alien to install the rpm package. I got this error when I just used the -i option. However when, I added -c I did not have this issue. from the man page for alien:
-c, --scripts
Try to convert the scripts that are meant to be run when the package is installed and removed. Use this with caution,
because these scripts might be designed to work on a system unlike
your own, and could cause problems. It is recommended that you
examine the scripts by hand and check to see what they do before using
this option.
So it seems the correct configuration (in 19c) or the environment variables (in earlier versions) are set in these scripts which are not generated unless you run alien like this. (Thanks #Christopher Jones for correcting me on this)
sudo alien -i -c BasicPackage.rpm
sudo alien -i -c SqlPlus.rpm
PERMISSIONS:
I want to stress the importance of permissions for "sqlplus".
For any "Other" UNIX user other than the Owner/Group to be able to run sqlplus and access an ORACLE database , read/execute permissions are required (rx) for these 4 directories :
$ORACLE_HOME/bin , $ORACLE_HOME/lib, $ORACLE_HOME/oracore, $ORACLE_HOME/sqlplus
Environment. Set those properly:
A. ORACLE_HOME
(example: ORACLE_HOME=/u01/app/oranpgm/product/12.1.0/PRMNRDEV/)
B. LD_LIBRARY_PATH
(example: ORACLE_HOME=/u01/app/oranpgm/product/12.1.0/PRMNRDEV/lib)
C. ORACLE_SID
D. PATH
export PATH="$ORACLE_HOME/bin:$PATH"
You can try usage:
# echo "/usr/lib/oracle/12.2/client64/lib" > /etc/ld.so.conf.d/oracle.conf
# ldconfig
This problem are because oracleinstant client not configure shared library.
Could you please check if LD_LIBRARY_PATH points to the oracle libs
Don't forget
apt-get install libaio1 libaio-dev
or
yum install libaio
On Oracle's own Linux (Version 7.7, PRETTY_NAME="Oracle Linux Server 7.7"
in /etc/os-release), if you installed the 18.3 client libraries with
sudo yum install oracle-instantclient18.3-basic.x86_64
sudo yum install oracle-instantclient18.3-sqlplus.x86_64
then you need to put the following in your .bash_profile:
export ORACLE_HOME=/usr/lib/oracle/18.3/client64
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib:$ORACLE_HOME
in order to be able to invoke the SQLPlus client, which, incidentally, is called sqlplus64 on this platform.
This worked for me: sudo dnf install libnsl
It means you didn't set ORACLE_HOME and ORACLE_SID variables. Kindly set proper working $ORACLE_HOME and $ORACLE_SID and after that execute sqlplus /nolog command. It will be working.
#laryx-decidua: I think you are only seeing the 18.x instant client releases that are in the ol7_oci_included repo. The 19.x instant client RPMs, at the moment, are only in the ol7_oracle_instantclient repo. Easiest way to access that repo is:
yum install oracle-release-el7

Node.js Cygwin not supported

I am trying to install node.js. I followed this tutorial and i am stuck in the middle.
When I write ./configure in my cygwin terminal it says "cygwin not supported". Please help me out
Thanks in advance.
Node in my experience runs fine in cygwin, what Node usually has EINVAL errors in seems to be MINTTY which is a terminal emulation 'skin' that is default to cygwin. I still am not sure why these EINVAL errors happen 100% but the following are the steps and tricks I use to get node working.
In my /cygwin/home/{username}/.bashrc I add node to path so cygwin can find it
export PATH=$PATH:"/cygdrive/c/Program Files/nodejs/"
If you run a 32 bit version of node:
export PATH=$PATH:"/cygdrive/c/Program Files (x86)/nodejs/"
Then to make npm run without windows to linux issues I launch cygwin in admin mode then run:
dos2unix '/cygdrive/c/Program Files/nodejs/npm'
At this point running files and most npm packages will run in MINTTY just fine, although every once and awhile you will run into EINVAL issues with certain npm packages as karma. Also you will not be able to run the interpreter directly in MINTTY, anytime I want to do these things I run:
cygstart /bin/bash
This will open a native cygwin bash.exe window, from here you run the interpreter or an any troubling package command that results in a EINVAL. It slightly sucks you have to do this but I rarely use this day to day, and I love MINTTY too much to not use it.
Also note that you can run any one line node code in MINTTY by just running something like:
node -e "console.log('hello node')"
As a simpler derivative of troy's answer for those just looking to install NPM packages:
Install Node.js with the Windows installer package.
Add it to the PATH with export PATH=$PATH:"/cygdrive/c/Program Files/nodejs/" (obviously replacing the path to Node.js's installation directory with where you installed it).
There's a current bug in the Windows version that can be fixed by running mkdir -p ~/AppData/Roaming/npm. This is a bug for all of Windows and not just Cygwin. At some point of the future, you won't have to do this anymore, but the command shouldn't have any negative side effects.
Test it. Eg, npm install pretty-diff -g.
In order to be able to run the newly installed software, you'll need to add the install locations to your PATH. You can find these with npm bin -g and npm bin (the -g flag is the "global" installation location).
Not really anything special that you have to do to get it to run in Cygwin (although I can't say if everything works).
Use Console2, it allows you to run create tabs of CLI shells. It seems running cygwin inside console2 allows me to use node REPL just fine. I have no idea why :P
Follow this guide to add cygwin to console2:
http://blog.msbbc.co.uk/2009/11/configuring-console-2-and-bash-with.html
With Bjørn's suggestion (using Console2) and Soyuka's alias (steps here), my node.js v0.10.13 and npm v1.3.2 are now working under Babun v1.02, a Cygwin distribution.
For windows, Just run bash.exe in cmd, so that you could have a bash work around with cmd console directly, which could support ALL NODE WORKING PERFECTLY.
C:\Users\郷>bash
郷#CHIGIX ~
$ node
>
I'm using this wrapper in /usr/local/bin/node (note no extension!)
#!/bin/sh
_cmd="$(cygpath -lw -- "$1" )"
shift
"/proc/cygdrive/C/Program Files/nodejs/node.exe" "$_cmd" "$#"
This is far from perfect, as Node do not understand Cygwin directory tree, but works relatively well with relative names.
From Windows, run Cygwin.bat (instead of Cygwin Terminal) then in that run node: see and reply on this answer on this effectively-same question asked 1.5 years later.
Grab and run the node.js Windows installer.
In the Cygwin prompt type node
See if it works.

Cygwin and PHPUnit: Could not open input file: /cygdrive/c/xampp/php/phpunit

Is there a way to run PHPUnit from Cygwin? Everytime I run PHPUnit I get this error:
Could not open input file: /cygdrive/c/xampp/php/phpunit
I am trying to run my unit tests in my Zend Framework App. I am trying to use Cygwin because I am more familiar with *Nix commands (I'm no expert though) rather than Windows.
Thanks,
Wenbert
same problem here, solved it by an alias added to ~/.bash_profile
alias phpunit="/cygdrive/c/xampp/php/php C:/xampp/php/phpunit"
I am having the same problem, I can't get "phpunit" to work by itself, I am using Wamp.
However, I was able to run "phpunit.bat" and it worked for me.
Still can't get the ANSI colors to show up though :(
Does /cygdrive/c/xampp/php/phpunit exist? If so what are the permissions on the file?
Try
ls -l /cygdrive/c/xampp/php/phpunit
Let's use phpunit as dependency and in folder above vendor try:
ln -s vendor/phpunit/phpunit/composer/bin/phpunit phpunit
It will create for you a symbolic link to real path of phpunit
You could just directly call it by using Windows path in Cygwin:
C:/xampp/php/phpunit --version
So you could set an alias for ~/.bash_profile:
alias phpunit="C:/xampp/php/phpunit"

Resources