首页 > 解决方案 > 如何修复“https://repo.packagist.org/packages.json 不包含有效的 Json”?

问题描述

我对在 vagrantbox(Centos 7)上运行的作曲家有疑问,它开始突然发生。

我已经尝试手动运行下面链接中提到的命令/解决方案,但无济于事。

(澄清一下,我使用的是 vagrant 而不是 docker,但这是我发现的最接近我的情况的问题。我发现的大部分信息都与 composer.json 无效有关,但这里是 packagist.org/packages.json其中,当前有效)

Composer 在 docker 容器中不起作用:“https://packagist.org/packages.json”不包含有效的 JSON

以下是问题的详细信息。

composer update在终端上运行时,我得到:

 composer update


  [Seld\JsonLint\ParsingException]
  "https://repo.packagist.org/packages.json" does not contain valid JSON
  Parse error on line 1:

  ^
  Expected one of: 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['

composer install也在终端上运行时,每个包都会返回:

Failed to download psr/cache from dist: "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8" 
appears broken, and returned an empty 200 response
    Now trying to download from source

运行composer config --global repo.packagist composer packagist.org 结果是现在

composer update
Loading composer repositories with package information


  [Composer\Downloader\TransportException]
  Your configuration does not allow connections to http://repo.packagist.org/packages.json. See https://getcomposer.o
  rg/doc/06-config.md#secure-http for details.

任何想法为什么会发生这种情况,我该如何解决?

标签: composer-phpvagrantsymfony4

解决方案


Could also be IPv6 related, if your provider/system is configured for IPv6 but has no valid IPv6 route out to the internet.

This happened to me, and doing sysctl -w net.ipv6.conf.all.disable_ipv6=1 (as root), then trying composer again fixed the issue.

To permanently apply it, add the rule to /etc/sysctl.conf (or wherever your OS preferred is)


推荐阅读