“loading composer repositories”卡住大概率因未配置https-proxy;composer对http/https请求走独立代理通道,仅设http-proxy会导致https仓库请求直连超时,必须同时执行composer config -g http-proxy和https-proxy且值均以http://开头。

“Loading composer repositories”卡住,大概率缺 https-proxy
Composer 对 HTTP 和 HTTPS 请求走完全独立的代理通道。只配 http-proxy,所有仓库请求(https://repo.packagist.org、GitHub 等)仍直连——结果就是卡在 “Loading composer repositories”,无报错、无进度、无限等待。
必须同时设置两个字段,缺一不可:
composer config -g http-proxy http://127.0.0.1:8080composer config -g https-proxy http://127.0.0.1:8080
注意:https-proxy 的值必须是 http:// 开头,哪怕你的代理本身监听 HTTPS 端口;填 https:// 或漏协议头会静默 fallback 到直连。
代理地址写错的典型现象和验证方式
填错 https-proxy 后不会报错,但你会看到这些现象:
- 执行
composer install -vvv时,日志停在Loading composer repositories,几秒后直接 timeout -
curl -x http://127.0.0.1:8080 -I https://packagist.org/packages.json也失败(407、Connection refused 或超时),说明代理层本身没通 - 运行
composer config -g --list | grep -E "(http|https)-proxy",发现只输出一行,或 URL 格式异常(如含未编码的@、/)
密码含特殊字符?用 php -r "echo rawurlencode('pa@ss/word');" 生成编码后填入,例如 http://user:pa%40ss%2Fword@127.0.0.1:8080。
NTLM 代理(如企业 Windows 域环境)不能直接配
Composer 原生不支持 NTLM 认证。设了 http-proxy 也会收到 407 Proxy Authentication Required 或直接连接失败。
必须引入中转代理工具:
- Windows 下推荐
cntlm或px,配置它们处理 NTLM 并监听127.0.0.1:3128 - 再让 Composer 连这个本地地址:
composer config -g http-proxy http://127.0.0.1:3128和https-proxy同理 - 验证:用
curl -x http://127.0.0.1:3128 -I https://packagist.org/packages.json看是否返回 200
别指望 HTTP_PROXY 环境变量——Composer 明确忽略它,只认自己的配置项。
镜像源 + 代理混用时的优先级陷阱
如果你既配了阿里云镜像(repo.packagist),又开了代理,实际请求路径是:composer → 代理 → 阿里云镜像。这没问题,但要注意两个关键点:
- 镜像 URL 必须带末尾斜杠:
https://mirrors.aliyun.com/composer/✅,少斜杠就静默失效 - 代理必须能访问该镜像域名;有些内网代理会拦截
mirrors.aliyun.com,此时反而要关代理、只换源
最稳的做法:先确认镜像是否生效(composer config -g repo.packagist 输出应为完整 JSON),再决定是否加代理。多数国内企业网,换源已足够,加代理反而多一层故障点。











