Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Composer behind http proxy

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?

like image 668
Robert Dolca Avatar asked Jun 25 '13 21:06

Robert Dolca


People also ask

How do I enter proxy URL in composer?

http_proxy or HTTP_PROXY# If you are using Composer from behind an HTTP proxy, you can use the standard http_proxy or HTTP_PROXY env vars. Simply set it to the URL of your proxy. Many operating systems already set this variable for you.

How do I change proxy settings on composer?

Your first installation of Composer added a variable named http_proxy to your environment. The value of http_proxy is what you see in that input. All you need to do is delete that variable from the environment and start the re-installation.


9 Answers

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.

like image 111
Felipe Avatar answered Oct 02 '22 15:10

Felipe


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.

like image 35
iconoclast Avatar answered Oct 02 '22 14:10

iconoclast


If you have to use credentials try this:

export HTTP_PROXY="http://username:[email protected]:port"
like image 32
chrisandrews7 Avatar answered Oct 02 '22 16:10

chrisandrews7


Try this:

export HTTPS_PROXY_REQUEST_FULLURI=false

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

like image 43
Nicolai Fröhlich Avatar answered Oct 02 '22 14:10

Nicolai Fröhlich


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

like image 37
diego matos - keke Avatar answered Oct 02 '22 16:10

diego matos - keke


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" "$@"
like image 35
softwarevamp Avatar answered Oct 02 '22 15:10

softwarevamp


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.

like image 31
Amr H. Abd Elmajeed Avatar answered Oct 02 '22 14:10

Amr H. Abd Elmajeed


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.

like image 24
Tom Sarduy Avatar answered Oct 02 '22 16:10

Tom Sarduy


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!

like image 39
Le Khiem Avatar answered Oct 02 '22 15:10

Le Khiem