Unable to update composer - connection timeout error

December 10, 2017 3.5k views
Networking Ubuntu 16.04

I am able to ssh into my droplet. Am also able to apt update and apt upgrade.

When I try to run sudo composer self-update or composer update, I am getting connection timeout error.

The "https://getcomposer.org/versions" file could not be downloaded: failed to open stream: Connection timed out  

output of ufw status

To                         Action      From

To Action From
22 Allow Anywhere
80/tcp ALLOW Anywhere
443/tcp ALLOW Anywhere
25/tcp ALLOW Anywhere
2525/tcp ALLOW Anywhere
10000/tcp ALLOW Anywhere

output of composer diagnose

Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: FAIL
[Composer\Downloader\TransportException] The "http://packagist.org/packages.json" file    could not be downloaded: failed to open stream: Connection timed out
Checking https connectivity to packagist: FAIL
[Composer\Downloader\TransportException] The "https://packagist.org/packages.json" file    could not be downloaded: failed to open stream: Connection timed out
Checking github.com rate limit: OK
Checking disk free space: OK
Checking composer version: 


  [Composer\Downloader\TransportException]                                     
  The "https://getcomposer.org/version" file could not be downloaded: failed   
  to open stream: Connection timed out

output of composer --version

Composer version 1.0-dev (9e9c1917e1ed9f3f78b195a785aee3c6dc3cb883) 2015-11-23 10:31:23  

output of curl IL http://packagist.org/packages.json

HTTP/1.1 200 OK
Server: nginx
Date: Sun, 10 Dec 2017 08:40:20 GMT
Content-Type: application/json
Content-Length: 1302
Last-Modified: Sun, 10 Dec 2017 08:38:28 GMT
Connection: keep-alive
ETag: "5a2cf284-516"
Cache-Control: private, max-age=0, no-cache
Accept-Ranges: bytes  

I tried to manually get a copy of latest composer but it also doesn't work

output of php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

PHP Warning:  copy(https://getcomposer.org/installer): failed to open stream: Connection timed out in Command line code on line 1  

What could be the reason? I was all working till about a week ago. I am able to visit (browse) the webpages hosted on my droplet.

2 Answers

The issue seems to be regarding the ipv6 setup. I really have no idea how to make it right on Digital Ocean droplet. However by setting the ipv4 traffic higher priority than the ipv6 does seem to be a working - workaround the issue as explained on Composer website.

I got the sudo composer self-update and composer update(from within a laravel project directory on do) working after the workaround. The composer update still runs very slow even with ** php7.0 **. Nonetheless it works.

Hope it helps someone else in a situation like me.

I have the following issue too

The "https://getcomposer.org/versions" file could not be downloaded: failed to open stream: Connection timed out
The download failed repeatedly, aborting.

I believe there is an issue with DO networking or most of their IP get banned.
I can run those command in my machine.

Have another answer? Share your knowledge.