http 代理背后的 PHP Composer
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17307600/
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
PHP Composer behind http proxy
提问by Robert Dolca
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:
我在网络上使用作曲家,其中访问互联网的唯一方法是使用 HTTP 或袜子代理。我有 http_proxy 和 https_proxy 环境变量。当 compose 尝试访问 HTTPS URL 时,我得到以下信息:
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?
据我所知,连接到 https 网站的唯一方法是使用连接动词。如何在此代理后面使用作曲家?
采纳答案by iconoclast
If you're on Linux or Unix (including OS X), you should put this somewhere that will affect your environment:
如果你在 Linux 或 Unix(包括 OS X)上,你应该把它放在会影响你的环境的地方:
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.
你可以把它放在/etc/profile
全局影响机器上的所有用户,或者你自己的~/.bashrc
或者~/.zshrc
,取决于你使用的shell。
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
.
如果您使用的是Windows,打开环境变量控制面板,以及带添加任何系统或用户环境变量HTTP_PROXY_REQUEST_FULLURI
,并HTTPS_PROXY_REQUEST_FULLURI
设置为0
或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.)
对于其他人阅读本(不是你的,因为你说你有这些设置),确保HTTP_PROXY
并HTTPS_PROXY
设置为正确的代理,使用同样的方法。如果你在 Unix/Linux/OS X 上,设置变量名的大写和小写版本是最完整的方法,因为有些东西只使用小写版本,而 IIRC 有些使用大写。(我经常使用一种混合环境,Windows 上的 Cygwin,我知道对我来说同时拥有这两种环境很重要,但纯 Unix/Linux 环境可能只用小写字母就可以逃脱。)
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 Cntlmas 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.
如果您在完成所有这些操作后仍然无法正常工作,并且您确定您设置了正确的代理地址,那么请查看您的公司是否正在使用 Microsoft 代理服务器。如果是这样,您可能需要安装Cntlm作为子代理来连接 Composer(等)和 Microsoft 代理服务器。谷歌 CNTLM 有关如何设置的更多信息和说明。
回答by Felipe
If you are using Windows, you should set the same environment variables, but Windows style:
如果您使用的是 Windows,您应该设置相同的环境变量,但 Windows 风格:
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.
这将适用于您当前的 cmd.exe。如果您想更持久地执行此操作,建议您在系统上使用环境变量。
回答by Nicolai Fr?hlich
Try this:
尝试这个:
export HTTPS_PROXY_REQUEST_FULLURI=false
solved this issue for me working behind a proxy at a company few weeks ago.
几周前,我在一家公司的代理后面为我解决了这个问题。
回答by chrisandrews7
If you have to use credentials try this:
如果您必须使用凭据,请尝试以下操作:
export HTTP_PROXY="http://username:[email protected]:port"
回答by diego matos - keke
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
替换为您的 IP 和端口
回答by softwarevamp
on Windows insert:
在 Windows 上插入:
set http_proxy=<proxy>
set https_proxy=<proxy>
before
前
php "%~dp0composer.phar" %*
or on Linux insert:
或在 Linux 上插入:
export http_proxy=<proxy>
export https_proxy=<proxy>
before
前
php "${dir}/composer.phar" "$@"
回答by Amr H. Abd Elmajeed
iconoclast's answer did not work for me.
iconoclast 的回答对我不起作用。
I upgraded my php from 5.3.* (xampp 1.7.4) to 5.5.* (xampp 1.8.3) and the problem was solved.
我将我的 php 从 5.3.* (xampp 1.7.4) 升级到 5.5.* (xampp 1.8.3),问题就解决了。
Try iconoclast's answer first, if it doesn't work then upgrading might solve the problem.
首先尝试 iconoclast 的答案,如果它不起作用,那么升级可能会解决问题。
回答by Tom Sarduy
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.
您可以使用标准HTTP_PROXY
环境变量。只需将其设置为代理的 URL。许多操作系统已经为您设置了这个变量。
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.
然后就可以composer update
正常进行了。
回答by Le Khiem
Operation timed out (IPv6 issues)# You may run into errors if IPv6 is not configured correctly. A common error is:
操作超时(IPv6 问题)# 如果 IPv6 配置不正确,您可能会遇到错误。一个常见的错误是:
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:
我们建议您修复 IPv6 设置。如果这是不可能的,您可以尝试以下解决方法:
Workaround Linux:
解决方法 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:
在 linux 上,似乎运行此命令有助于使 ipv4 流量具有比 ipv6 更高的优先级,这比完全禁用 ipv6 更好:
sudo sh -c "echo 'precedence ::ffff:0:0/96 100' >> /etc/gai.conf"
Workaround Windows:
解决方法 Windows:
On windows the only way is to disable ipv6 entirely I am afraid (either in windows or in your home router).
在 Windows 上,唯一的方法是完全禁用 ipv6(在 Windows 中或在您的家庭路由器中)。
Workaround Mac OS X:
解决方法 Mac OS X:
Get name of your network device:
获取网络设备的名称:
networksetup -listallnetworkservices
Disable IPv6 on that device (in this case "Wi-Fi"):
在该设备上禁用 IPv6(在本例中为“Wi-Fi”):
networksetup -setv6off Wi-Fi
Run composer ...
运行作曲家...
You can enable IPv6 again with:
您可以再次启用 IPv6:
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.
也就是说,如果这解决了您的问题,请与您的 ISP 联系以尝试解决路由错误。这是为每个人解决问题的最佳方式。
Hoping it will help you!
希望能帮到你!
回答by Charles
according to above ideas, I created a shell script that to make a proxy environment for composer.
根据上面的想法,我创建了一个shell脚本来为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.
这段代码在一个名为的文件中~/bin/proxy_mode_shell
,zsh
当您需要代理时,它将创建一个新的shell 实例。更新完成后,您可以简单地按 键Ctrl+D
退出代理模式。
add export PATH=~/bin:$PATH
to ~/.bashrc
or ~/.zshrc
if you cannot run proxy_mode_shell
directly.
添加export PATH=~/bin:$PATH
到~/.bashrc
或~/.zshrc
如果您不能proxy_mode_shell
直接运行。