Composer 无法下载文件

2022-01-21 00:00:00 php composer-php

我正在尝试在命令行上使用作曲家:

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

我支持代理.如果我使用浏览器并键入与不能使用命令行的 URL 相同的 URL,则没有问题.

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.

我该怎么办?

推荐答案

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

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.

例如:

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

如果您在 Linux/OS X 或 Windows 环境设置中将其放入 bashrc,则会获得奖励积分.

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

相关文章