I have a qemu linux virtual machine and I'm trying to install composer on it using the commands on the composer page. I'm on a windows network accessing the internet through a proxy that uses ntlm, so I use cntlm to authenticate linux and other programs on my PC (thanks to the people that created cntlm). I added the context to the copy command needed to access the proxy but it doesn't work.
This are the command used so far:
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php', stream_context_create(['https' => ['proxy' => 'http://10.0.2.2:3128/']]));"
# a variant
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php', stream_context_create(['https' => ['proxy' => 'tcp://10.0.2.2:3128/']]));"
The answer is:
PHP Warning: copy(https://getcomposer.org/installer): failed to open stream: Connection timed out in Command line code on line 1
Download the file using wget works fine.
$ env | grep "proxy"
https_proxy=http://10.0.2.2:3128/
http_proxy=http://10.0.2.2:3128/
$ wget -O composer-setup.php https://getcomposer.org/installer
--2017-09-XX XX:XX:XX-- https://getcomposer.org/installer
Connecting to 10.0.2.2:3128 ... conected
Request send ... 200 OK
... etc
2017-09-XX XX:XX:XX (XX KB/s) - composer-setup.php saved [305728/305728]
The sites used as reference:
I know there is a manual way to install composer, but I'm just a bit curious, How can make this work?
There is no https
option for stream_context_create()
, there is only http
which affects both http
and https
protocols:
Context options for
http://
andhttps://
transports.
https://php.net/manual/en/context.http.php
So you should probably use something like this:
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php', stream_context_create(['http' => ['proxy' => 'tcp://10.0.2.2:3128']]));"
You don't necessarily have to do the download with PHP.
Since the wget download works you can:
wget -O composer-setup.php https://getcomposer.org/installer
export EXPECTED_HASH=$(wget -q -O - https://composer.github.io/installer.sig)
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$EXPECTED_HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With