Laravel – “https://packagist.org/packages.json” file could not be downloaded: failed to open stream: Operation timed out

composer-phplaravel

This morning, I ran this command

composer create-project laravel/laravel laravel-4.2 4.2 --prefer-dist

I kept getting

enter image description here

The "https://packagist.org/packages.json" file could not be downloaded: failed to open stream: Operation timed out
Retrying with degraded mode, check https://getcomposer.org/doc/articles/troubleshooting.md#degraded-mode for more info

Anyone know how to avoid this ?

Best Answer

For me, this wasn't an issue with my internet connection speed, but it was a issue with IPv6 resolution of "repo.packagist.org". I got around this issue by adding the IPv4 address to my hosts file. It's a hack, but it works.

# dig +short repo.packagist.org
142.44.164.255
# echo "142.44.164.255 repo.packagist.org" >> /etc/hosts

More details here!