Skip to content

Instantly share code, notes, and snippets.

@oanhnn
Created May 14, 2017 16:47
Show Gist options
  • Save oanhnn/112f68e5b91a7dac7641bcd8b0ab13ac to your computer and use it in GitHub Desktop.
Save oanhnn/112f68e5b91a7dac7641bcd8b0ab13ac to your computer and use it in GitHub Desktop.
How to fix composer error "Content-Length Mismatch"

First, run:

$ composer config --list --global        //this will get the composer home path.
[home] /root/.composer                   //it's my composer home path.

And then, edit the config.json in [home] directory, make it like this:

{
  "config": {
    "github-protocols": [
      "https,ssh"
    ]
  },
  "repositories": {
    "packagist": {
      "type": "composer",
      "url": "https://packagist.org"
    }
  }
}

It will make the packagist connection force https. And also you could config the composer.json in your project, this is a laravel sample would be look like:

{
  "name": "laravel/laravel",
  "description": "The Laravel Framework.",
  "keywords": [
    "framework",
    "laravel"
  ],
  "license": "MIT",
  "type": "project",
  "require": {
    "php": ">=5.5.9",
    "laravel/framework": "5.2.*"
  },
  "config": {
    "preferred-install": "dist"
  },
  "repositories": {
    "packagist": {
      "type": "composer",
      "url": "https://packagist.org"
    }
  }
}

Source: http://stackoverflow.com/questions/38635257/composer-content-length-mismatch

@whitesec-au
Copy link

Nothing works for me. Trying to create a new yii project using composer. Anyone had the same problem with creating a new Yii2 framework project?

@df-a
Copy link

df-a commented Sep 28, 2020

@whitesec-au in my case it was the following

"repositories": {
"packagist": {
"type": "composer",
"url": "https://packagist.org"
}
}

I had "https://asset-packagist.org" instead of just "https://packagist.org". I changed that and it worked

@Vetjurv4
Copy link

Vetjurv4 commented Nov 5, 2020

$ composer config -g repo.packagist composer https://packagist.org
$ composer config -g github-protocols https ssh

This does the same job :)

Thank you this worked for me

@ojchris
Copy link

ojchris commented Mar 7, 2021

$ composer config -g repo.packagist composer https://packagist.org
$ composer config -g github-protocols https ssh

This does the same job :)

This resolved the issue for me

@RogueCode007
Copy link

Still getting a content-length mismatch error even after trying the above mentioned solutions. This happens when I'm trying to create a new laravel project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment