PHP Composer behind http proxy
Asked Answered
S

10

37

I use composer on a network where the only way to access the internet is using HTTP or socks proxy. I have http_proxy and https_proxy environment variables. When compose tries to access HTTPS URLs I get this:

 file could not be downloaded: failed to open stream: Cannot connect to HTTPS server through proxy

As far as I know the only way to connect to a https website is using a connect verb. How can I use composer behind this proxy?

Symphony answered 25/6, 2013 at 21:10 Comment(9)
Does this not answer your question? -- stackoverflow.com/questions/15268093Marivelmariya
As I said I have HTTP_PROXY / http_proxy environment variableSymphony
Maybe your openssl extension is outdated github.com/composer/composer/issues/2021Zimmermann
Run composer diag to check your connection. Composer has two methods of talking to proxys, and probably the one being used is wrong.Pellagra
@Zimmermann OpenSSL version is 1.0.1.x and I am experiencing the same issue like boldtrn on Ubuntu 12.04.Symphony
@Pellagra Checking HTTP proxy: OK Checking HTTP proxy support for request_fulluri: OK Checking HTTPS proxy support for request_fulluri: FAIL Unable to assert the situation, maybe github is down (The "api.github.com/repos/Seldaek/jsonlint/zipball/1.0.0" file could not be downloaded: failed to open stream: Cannot connect to HTTPS server through proxy)Symphony
Bad thing - that's what I'm getting also with my proxy, and I haven't got a solution. For my situation, I suspect the OpenSSL in PHP is the faulty 0.9.8 series that needs some tweaks. The Composer project definitely will need some help in this, because proxys are a real pain to work with, so if you would open an issue on github and provide as much info as possible, everyone will eventually enjoy a solution.Pellagra
github.com/composer/composer/issues/2041Symphony
We are developing on Zend Server. There is no option to update built in OpenSSL libraries. Somehow funny because ZF2 applications in Zend Studio "are based" on Composer features. It kept me hours to find no solution.Atonement
I
36

If you're on Linux or Unix (including OS X), you should put this somewhere that will affect your environment:

export HTTP_PROXY_REQUEST_FULLURI=0 # or false
export HTTPS_PROXY_REQUEST_FULLURI=0 #

You can put it in /etc/profile to globally affect all users on the machine, or your own ~/.bashrc or ~/.zshrc, depending on which shell you use.

If you're on Windows, open the Environment Variables control panel, and add either a system or user environment variables with both HTTP_PROXY_REQUEST_FULLURI and HTTPS_PROXY_REQUEST_FULLURI set to 0 or false.

For other people reading this (not you, since you said you have these set up), make sure HTTP_PROXY and HTTPS_PROXY are set to the correct proxy, using the same methods. If you're on Unix/Linux/OS X, setting both upper and lowercase versions of the variable name is the most complete approach, as some things use only the lowercase version, and IIRC some use the upper case. (I'm often using a sort of hybrid environment, Cygwin on Windows, and I know for me it was important to have both, but pure Unix/Linux environments might be able to get away with just lowercase.)

If you still can't get things working after you've done all this, and you're sure you have the correct proxy address set, then look into whether your company is using a Microsoft proxy server. If so, you probably need to install Cntlm as a child proxy to connect between Composer (etc.) and the Microsoft proxy server. Google CNTLM for more information and directions on how to set it up.

Idealize answered 9/8, 2013 at 21:24 Comment(0)
P
44

If you are using Windows, you should set the same environment variables, but Windows style:

set http_proxy=<your_http_proxy:proxy_port>
set https_proxy=<your_https_proxy:proxy_port>

That will work for your current cmd.exe. If you want to do this more permanent, y suggest you to use environment variables on your system.

Prig answered 17/9, 2013 at 14:1 Comment(1)
If you need credentials do SET HTTP_PROXY=http://%USER%:%PASSWORD%@%SERVER%:%PORT%Dhow
I
36

If you're on Linux or Unix (including OS X), you should put this somewhere that will affect your environment:

export HTTP_PROXY_REQUEST_FULLURI=0 # or false
export HTTPS_PROXY_REQUEST_FULLURI=0 #

You can put it in /etc/profile to globally affect all users on the machine, or your own ~/.bashrc or ~/.zshrc, depending on which shell you use.

If you're on Windows, open the Environment Variables control panel, and add either a system or user environment variables with both HTTP_PROXY_REQUEST_FULLURI and HTTPS_PROXY_REQUEST_FULLURI set to 0 or false.

For other people reading this (not you, since you said you have these set up), make sure HTTP_PROXY and HTTPS_PROXY are set to the correct proxy, using the same methods. If you're on Unix/Linux/OS X, setting both upper and lowercase versions of the variable name is the most complete approach, as some things use only the lowercase version, and IIRC some use the upper case. (I'm often using a sort of hybrid environment, Cygwin on Windows, and I know for me it was important to have both, but pure Unix/Linux environments might be able to get away with just lowercase.)

If you still can't get things working after you've done all this, and you're sure you have the correct proxy address set, then look into whether your company is using a Microsoft proxy server. If so, you probably need to install Cntlm as a child proxy to connect between Composer (etc.) and the Microsoft proxy server. Google CNTLM for more information and directions on how to set it up.

Idealize answered 9/8, 2013 at 21:24 Comment(0)
S
8

If you have to use credentials try this:

export HTTP_PROXY="http://username:[email protected]:port"
Singles answered 19/9, 2014 at 13:5 Comment(1)
I also had to set HTTP_PROXY_REQUEST_FULLURI back to 1 and encode my password properly on Windows.Welloiled
A
7

Try this:

export HTTPS_PROXY_REQUEST_FULLURI=false

solved this issue for me working behind a proxy at a company few weeks ago.

Abingdon answered 26/6, 2013 at 23:15 Comment(2)
@RobertDolca: check out my answer, and let me know if that still doesn't help. I've had to deal with this problem recently, so hopefully I can help you get it working.Idealize
I am sorry but I can not reproduce the issue nowSymphony
H
6

This works , this is my case ...

C:\xampp\htdocs\your_dir>SET HTTP_PROXY="http://192.168.1.103:8080" 

Replace with your IP and Port

Horribly answered 22/4, 2016 at 19:26 Comment(1)
I had accidentally added a trailing slash. After removing it, composer-setup was able to proceed. Other tools (wget...) seem to ignore that slash.Coated
C
3

on Windows insert:

set http_proxy=<proxy>
set https_proxy=<proxy>

before

php "%~dp0composer.phar" %*

or on Linux insert:

export http_proxy=<proxy>
export https_proxy=<proxy>

before

php "${dir}/composer.phar" "$@"
Colonic answered 5/6, 2018 at 1:6 Comment(0)
S
2

iconoclast's answer did not work for me.

I upgraded my php from 5.3.* (xampp 1.7.4) to 5.5.* (xampp 1.8.3) and the problem was solved.

Try iconoclast's answer first, if it doesn't work then upgrading might solve the problem.

Sigismund answered 30/9, 2013 at 15:4 Comment(0)
B
2

You can use the standard HTTP_PROXY environment var. Simply set it to the URL of your proxy. Many operating systems already set this variable for you.

Just export the variable, then you don't have to type it all the time.

export HTTP_PROXY="http://johndoeproxy.cu:8080"

Then you can do composer update normally.

Bestial answered 16/8, 2014 at 7:32 Comment(0)
S
2

Operation timed out (IPv6 issues)# You may run into errors if IPv6 is not configured correctly. A common error is:

The "https://getcomposer.org/version" file could not be downloaded: failed to
open stream: Operation timed out

We recommend you fix your IPv6 setup. If that is not possible, you can try the following workarounds:

Workaround Linux:

On linux, it seems that running this command helps to make ipv4 traffic have a higher prio than ipv6, which is a better alternative than disabling ipv6 entirely:

sudo sh -c "echo 'precedence ::ffff:0:0/96 100' >> /etc/gai.conf"

Workaround Windows:

On windows the only way is to disable ipv6 entirely I am afraid (either in windows or in your home router).

Workaround Mac OS X:

Get name of your network device:

networksetup -listallnetworkservices

Disable IPv6 on that device (in this case "Wi-Fi"):

networksetup -setv6off Wi-Fi

Run composer ...

You can enable IPv6 again with:

networksetup -setv6automatic Wi-Fi

That said, if this fixes your problem, please talk to your ISP about it to try and resolve the routing errors. That's the best way to get things resolved for everyone.

Hoping it will help you!

Suitcase answered 7/7, 2019 at 4:44 Comment(0)
O
0

according to above ideas, I created a shell script that to make a proxy environment for composer.

#!/bin/bash
export HTTP_PROXY=http://127.0.0.1:8888/
export HTTPS_PROXY=http://127.0.0.1:8888/
zsh # you can alse use bash or other shell

This piece of code is in a file named ~/bin/proxy_mode_shell and it will create a new zsh shell instance when you need proxy. After update finished, you can simply press key Ctrl+D to quit the proxy mode.

add export PATH=~/bin:$PATH to ~/.bashrc or ~/.zshrc if you cannot run proxy_mode_shell directly.

Oyster answered 9/2, 2017 at 12:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.