php Composer 无法下载文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15268093/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 08:56:06  来源:igfitidea点击:

Composer cannot download files

phpcomposer-php

提问by mlwacosmos

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.

我在代理后面。如果我使用浏览器并键入与无法使用命令行的 URL 相同的 URL,则没有问题。

What should I do?

我该怎么办?

回答by Tim Groeneveld

If you are using composer from behind an HTTP proxy, you can use the standard http_proxyor HTTP_PROXYenv vars. Simply set it to the URL of your proxy. Many operating systems already set this variable for you.

如果您在 HTTP 代理后面使用 composer,您可以使用标准http_proxy或环境HTTP_PROXY变量。只需将其设置为代理的 URL。许多操作系统已经为您设置了这个变量。

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.

如果您在 Linux/OS X 上或您的 Windows 环境设置中将其放入 bashrc 中,则可获得加分。

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

回答by Oriam

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:

在代理下的 Windows 上运行 composer 的正确简单方法是打开控制台(cmd),转到您的项目位置并运行以下命令:

C:\wamp\htdocs\myproject\> SET HTTP_PROXY=http://username:[email protected]:8080 && php composer.phar install

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

PD:您必须将用户名、密码、proxy.yourdomain.com 和 8080 等参数更改为您的

I hope this help to you

我希望这对你有帮助

回答by mp31415

And DO NOT set https_proxy(just http_proxy)!

并且不要设置https_proxy(只是http_proxy)!