在 Windows 7 上使用代理安装 Composer 时出现 SSL 验证失败错误

在 Windows 7 上使用代理安装 Composer 时出现 SSL 验证失败错误

我的错误是,每当我尝试使用 GUI 和命令行安装 Composer 时,我都会收到相同的错误,SSL 验证失败,因此无法通过我的代理连接到 HTTP。我在一台 Windows 7 计算机上,在代理后面运行 XAMPP。

首先,我对这个错误进行了研究,并尝试了其他帖子上的所有解决方案,我想知道我错过了什么。

我尝试过的事情:

  • 目前正在使用 XAMPP for apache,我下载并安装了最新版本以及一些以前的版本
  • 我重新下载了 curl-ca-bundle.crt 并更新了我的 \xampp\apache\bin\curl-ca-bundle.crt 以反映最新版本(XAMPP 附带的版本和我下载的版本之间大约有 20kb 的差异)。
  • 我手动下载了 getcomposer.org 的证书并将其附加到 curl-ca-bundle.crt 的末尾。(是的,我确信这是 PHP/Composer 用于安装的文件)
  • 当我尝试通过命令行安装时,出现错误,提示没有这样的主机。我发现这个问题是由于未设置 HTTP/HTTPS_PROXY URL 造成的。我打开了它们,然后出现了与通过 GUI 相同的错误(如下所示)
  • 然后,当我通过 Composer 的网站并下载 .exe 进行安装时,在安装程序中,我可以选择指定代理(我这样做了)以摆脱无 sush 主机,在我指定代理后,我现在遇到与命令行完全相同的错误。
  • 禁用 Composer 的 SSL/TLS。但尝试使用 https 连接任何网站时仍会失败。

图形用户界面(GUI):

Composer 安装程序脚本未成功 [退出代码 1]。

OpenSSL 失败,出现“证书验证失败”错误。这表明您系统上的证书颁发机构文件存在问题,可能已过期。

证书位置[来自 openssl.cafile ini 设置]:\xampp\apache\bin\curl-ca-bundle.crt

您的命令行 PHP 使用的 php.ini 是:C:\xampp\php\php.ini

脚本输出:“https://getcomposer.org/versions“无法下载文件:SSL 操作失败,代码为 1。OpenSSL 错误消息:错误:1416F086:SSL 例程:tls_process_server_certificate:证书验证失败,无法打开流:无法通过代理连接到 HTTPS 服务器

命令行:

C:\Users\S0077500\Desktop\Laravel\Attempt 7>php composer.phar diagnose
You are running Composer with SSL/TLS protection disabled.
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: WARNING
[Composer\Downloader\TransportException] The "https://repo.packagist.org/package
s.json" file could not be downloaded: SSL operation failed with code 1. OpenSSL
Error messages:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify fa
iled
failed to open stream: Cannot connect to HTTPS server through proxy
Composer is configured to disable SSL/TLS protection. This will leave remote HTT
PS requests vulnerable to Man-In-The-Middle attacks.
Checking HTTP proxy: FAIL
[Composer\Downloader\TransportException] The "https://repo.packagist.org/package
s.json" file could not be downloaded: SSL operation failed with code 1. OpenSSL
Error messages:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify fa
iled
failed to open stream: Cannot connect to HTTPS server through proxy
Checking HTTP proxy support for request_fulluri: OK
Checking HTTPS proxy support for request_fulluri: Unable to assess the situation
, maybe github is down (The "https://api.github.com/repos/Seldaek/jsonlint/zipba
ll/1.0.0" file could not be downloaded: SSL operation failed with code 1. OpenSS
L Error messages:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify fa
iled
failed to open stream: Cannot connect to HTTPS server through proxy)
Checking github.com rate limit: FAIL
[Composer\Downloader\TransportException] The "https://api.github.com/rate_limit"
 file could not be downloaded: SSL operation failed with code 1. OpenSSL Error m
essages:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify fa
iled
failed to open stream: Cannot connect to HTTPS server through proxy
Checking disk free space: OK
Checking pubkeys: FAIL
Missing pubkey for tags verification
Missing pubkey for dev verification
Run composer self-update --update-keys to set them up
Checking composer version:

  [Composer\Downloader\TransportException]
  The "https://getcomposer.org/versions" file could not be downloaded: SSL op
  eration failed with code 1. OpenSSL Error messages:
  error:1416F086:SSL routines:tls_process_server_certificate:certificate veri
  fy failed
  failed to open stream: Cannot connect to HTTPS server through proxy


diagnose


C:\Users\S0077500\Desktop\Laravel\Attempt 7>

答案1

我有 Windows 10,装有 xampp 3.0.12(php5.3)。我无法安装 Composer。我尝试了以下步骤,它对我有用。

  1. 从以下位置下载安装程序脚本https://getcomposer.org/installer
  2. 将其保存在名为 的文件中composer-setup.php
  3. 在您最喜欢的编辑器中打开composer-setup.php
  4. 将所有 HTTPS 替换为 HTTP 并保存文件。
  5. 在命令提示符中执行以下 3 个步骤:

    php -r "if (hash_file('sha384', 'composer-setup.php') === 'a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
    
    php composer-setup.php
    
    php -r "unlink('composer-setup.php');"
    
  6. 瞧!Composer 安装成功,您可以运行:php composer.phar

谢谢

答案2

我遇到了同样的错误。这是我解决问题的方法。我按照https://getcomposer.org/download/,以下段落命令行安装

```
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
```

我更换了php composer-setup.phpphp composer-setup.php --disable-tls

不需要编辑 php 脚本。

我是在查看 composer-setup.php 中的代码时找到了这个选项的。我应该跑去php composer-setup.php --help更快地找到相同的答案,而不用阅读代码。

相关内容