Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composer Content-Length Mismatch

Sometimes when I run composer update to upgrade the laravel project, a content-length mismatch exception might occur. Finally, I get this is because of the terrible firewall in China: the DNS was poisoned. So, if you are like me, could there be a way to fix it out?

like image 274
Alex Chiang Avatar asked Jul 28 '16 11:07

Alex Chiang


1 Answers

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, make it like this:

{   "config": {     "github-protocols": [       "https"     ]   },   "repositories": {     "packagist.org": {       "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.org": {       "type": "composer",       "url": "https://packagist.org"     }   } } 

Update

Before Composer v1.2.3 the repository key for packagist was "packagist". In v1.2.3 it was changed to "packagist.org" (see commit e38ebef).

like image 114
Alex Chiang Avatar answered Oct 07 '22 16:10

Alex Chiang