使用 NTLM 身份验证在代理服务器后面的 Windows 上安装 Symfony

Install Symfony on Windows behind proxy server with NTLM authentication

我试图在我公司的服务器上下载并安装 Symfony...

c:\> php -r "readfile('http://symfony.com/installer');" > symfony

..并得到以下错误(部分是德语,但你会明白的):

PHP Warning:  readfile(http://symfony.com/installer): failed to open stream: Es konnte keine Verbindung hergestellt werd en, da der Zielcomputer die Verbindung verweigerte.
 in Command line code on line 1

所以我通过浏览器手动下载了它(效果很好)并尝试创建一个新站点:

php symfony.phar new blog

现在我得到这个错误:

[RuntimeException]
There was an error downloading Symfony from symfony.com server:
Client error response [url] http://symfony.com/download?v=Symfony_Standard_Vendors_latest.tgz [status code] 407 [re
ason phrase] Proxy Authentication Required

[GuzzleHttp\Exception\ClientException]
Client error response [url] http://symfony.com/download?v=Symfony_Standard_Vendors_latest.tgz [status code] 407 [re
ason phrase] Proxy Authentication Required

所以我退后一步,看看是否可以在 PHP 脚本中执行 cURL 请求。我用下面的脚本试了一下(我公司用的是NTLM认证的代理服务器):

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.google.com');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, 'proxy.company.loc');
curl_setopt($ch, CURLOPT_PROXYPORT, 8080);
curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'user:password');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
echo curl_exec($ch);
curl_close($ch);

而且效果很好。

我需要做什么才能安装和使用 Symfony。在哪里定义代理、凭据和 NTLM 方法?我尝试在环境变量中添加 HTTP_PROXY 作为“http://user:password@proxy.company.loc:8080”,但这没有帮助(也许我还必须在某处添加身份验证类型 NTLM)。

服务器是 Windows Server 2012 R2。 PHP 版本是 5.6.5,Apache 是 2.4.12。

感谢您的帮助,对于任何语法错误,我们深表歉意!

我将描述我自己使用的解决方案。

  1. 下载cntlm-0.92.3-setup.exe并安装(它将设置系统服务)。
  2. 配置cntlm.ini(C:\Program Files (x86)\Cntlm\cntlm.ini)-代理地址,无代理,域帐号等
  3. 重新启动 Cntlm 身份验证代理服务。
  4. 将 http_proxy/https_proxy 设置为 http://localhost:3128(系统范围方法)
  5. 立即尝试 symfony 安装程序

有时它可能会有点慢,但它确实有效。我将此解决方案用于所有不支持与系统范围代理集成的控制台应用程序。 Cntlm 也适用于基于 unix 的 OS.

希望对您有所帮助。