16

I am trying to use composer on command line :

php composer.phar update
php composer.phar install
php composer.phar self-update
php composer.phar selfupdate

Whatever I do I always receive the same error message:

File could not be downloaded. Failed to open stream

I am behind a proxy. If I use a browser and type the same URLs as the ones that didn't work with command line, there is no problem.

What should I do?

mlwacosmos
  • 4,391
  • 16
  • 66
  • 114

3 Answers3

21

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.

eg:

 HTTP_PROXY="http://my-corp-proxy.mcdonalds" php composer.phar install

bonus points if you throw it into your bashrc if your on Linux/OS X or your environment settings for Windows.

To make it easier, you can just export the variable, then you don't have to type it all the time.

 export HTTP_PROXY="http://my-corp-proxy.mcdonalds"
 php composer.phar install
Tim Groeneveld
  • 8,739
  • 3
  • 44
  • 60
  • Excuse me I am really a newbie concerning the network thing and proxy.. I have no access to the proxy because I work in a company, I am with windows 7... what is the url after the HTTP_PROXY ? – mlwacosmos Mar 07 '13 at 10:22
  • 2
    @mlwacosmos on Win7 to add an environment variable you can follow this guide: http://www.itechtalk.com/thread3595.html you need to define HTTP_PROXY as variable name and `http://your.proxy.address.or.ip/` as value. Then you must restart CMD for composer to see the changes. – Seldaek Mar 07 '13 at 11:08
10

The right an easy way to run composer on windows under a proxy is opening the console (cmd), go to your project location and run this command:

C:\wamp\htdocs\myproject\> SET HTTP_PROXY=http://username:password@proxy.yourdomain.com:8080 && php composer.phar install

PD: You must changes parameters like: username, password, proxy.yourdomain.com and 8080 to yours

I hope this help to you

Oriam
  • 641
  • 10
  • 19
2

And DO NOT set https_proxy (just http_proxy)!

mp31415
  • 6,531
  • 1
  • 44
  • 34