Laravel - composer update: Connection refused

2019-07-16 10:33发布

问题:

When I do $ composer update on prod server, I get this message:

[Composer\Downloader\TransportException]
The "https://larapack.io/packages.json" file could not be downloaded: 
failed to open stream: Connection refused

It used to work fine a month ago.

Here is the list of my installed packages (if it helps):

arrilot/laravel-widgets               3.9.0   A powerful alternative to view composers. Asynchronous widgets, reloadable widgets, console...
balping/json-raw-encoder              v1.0.0  Encode arrays to json with raw JS objects (eg. callbacks) in them
composer/ca-bundle                    1.1.0   Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bun...composer/composer                     1.6.2   Composer helps you declare, manage and install dependencies of PHP projects, ensuring you h...
composer/semver                       1.4.2   Semver library that offers utilities, version constraint parsing and validation.composer/spdx-licenses                1.2.0   SPDX licenses list and validation library.
consoletvs/charts                     6.2.1   The laravel charting packagednoegel/php-xdg-base-dir              0.1     implementation of xdg base directory specification for php
doctrine/annotations                  v1.6.0  Docblock Annotations Parserdoctrine/cache                        v1.7.1  Caching library offering an object-oriented API for many cache backends
doctrine/collections                  v1.5.0  Collections Abstraction librarydoctrine/common                       v2.8.1  Common Library for Doctrine projects
doctrine/dbal                         v2.6.3  Database Abstraction Layerdoctrine/inflector                    v1.3.0  Common String Manipulations with regard to casing and singular/plural rules.
doctrine/instantiator                 1.1.0   A small, lightweight utility to instantiate objects in PHP without invoking their constructorsdoctrine/lexer                        v1.0.1  Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
egulias/email-validator               2.1.3   A library for validating emails against several RFCserusev/parsedown                      1.6.4   Parser for Markdown.
fideloper/proxy                       3.3.4   Set trusted proxies for Laravelfilp/whoops                           2.1.14  php error handling for cool kids
fzaninotto/faker                      v1.7.1  Faker is a PHP library that generates fake data for you.
geoip2/geoip2                         v2.8.0  MaxMind GeoIP2 PHP API
gloudemans/shoppingcart               2.5.0   Laravel Shoppingcart
guzzlehttp/psr7                       1.4.2   PSR-7 message implementation that also provides common utility methods
hamcrest/hamcrest-php                 v2.0.0  This is the PHP port of Hamcrest Matchers
intervention/image                    2.4.1   Image handling and manipulation library with support for Laravel integration
jakub-onderka/php-console-color       0.1
jakub-onderka/php-console-highlighter v0.3.2
justinrainbow/json-schema             5.2.6   A library to validate a json schema.
larapack/doctrine-support             v0.1.4  Better Doctrine Support with Laravel (Support for `enum`)
larapack/hooks                        v1.0.1  A Laravel Hook system
larapack/voyager-hooks                v1.0.4  Hooks integrated in Voyager
laravel/framework                     v5.5.28 The Laravel Framework.
laravel/tinker                        v1.0.3  Powerful REPL for the Laravel framework.
league/flysystem                      1.0.41  Filesystem abstraction: Many filesystems, one API.
maxmind-db/reader                     v1.3.0  MaxMind DB Reader API
maxmind/web-service-common            v0.5.0  Internal MaxMind Web Service API
mockery/mockery                       1.0     Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHP...
monolog/monolog                       1.23.0  Sends your logs to files, sockets, inboxes, databases and various web services
mtdowling/cron-expression             v1.2.1  CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is...
myclabs/deep-copy                     1.7.0   Create deep copies (clones) of your objects
nesbot/carbon                         1.22.1  A simple API extension for DateTime.
nikic/php-parser                      v3.1.3  A PHP parser written in PHP
paragonie/random_compat               v2.0.11 PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
phar-io/manifest                      1.0.1   Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                       1.0.1   Library for handling version information and constraints
phpdocumentor/reflection-common       1.0.1   Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock     4.2.0   With this component, a library can provide support for annotations via DocBlocks or otherwi...
phpdocumentor/type-resolver           0.4.0
phpspec/prophecy                      1.7.3   Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage             5.3.0   Library that provides collection, processing, and rendering functionality for PHP code cove...
phpunit/php-file-iterator             1.4.5   FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-text-template             1.2.1   Simple template engine.
phpunit/php-timer                     1.0.9   Utility class for timing
phpunit/php-token-stream              2.0.2   Wrapper around PHP's tokenizer extension.
phpunit/phpunit                       6.5.5   The PHP Unit Testing framework.
phpunit/phpunit-mock-objects          5.0.6   Mock Object library for PHPUnit
psr/container                         1.0.0   Common Container Interface (PHP FIG PSR-11)
psr/http-message                      1.0.1   Common interface for HTTP messages
psr/log                               1.0.2   Common interface for logging libraries
psr/simple-cache                      1.0.0   Common interfaces for simple caching
psy/psysh                             v0.8.17 An interactive shell for modern PHP.
ramsey/uuid                           3.7.1   Formerly rhumsaa/uuid. A PHP 5.4+ library for generating RFC 4122 version 1, 3, 4, and 5 un...
sebastian/code-unit-reverse-lookup    1.0.1   Looks up which function or method a line of code belongs to
sebastian/comparator                  2.1.1   Provides the functionality to compare PHP values for equality
sebastian/diff                        2.0.1   Diff implementation
sebastian/environment                 3.1.0   Provides functionality to handle HHVM/PHP environments
sebastian/exporter                    3.1.0   Provides the functionality to export PHP variables for visualization
sebastian/global-state                2.0.0   Snapshotting of global state
sebastian/object-enumerator           3.0.3   Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector            1.1.1   Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context           3.0.0   Provides functionality to recursively process PHP variables
sebastian/resource-operations         1.0.0   Provides a list of PHP built-in functions that operate on resources
sebastian/version                     2.0.1   Library that helps with managing the version number of Git-hosted PHP projects
seld/cli-prompt                       1.0.3   Allows you to prompt for user input on the command line, and optionally hide the characters...
seld/jsonlint                         1.7.0   JSON Linter
seld/phar-utils                       1.0.1   PHAR file format utilities, for when PHP phars you up
simshaun/recurr                       v3.0.5  PHP library for working with recurrence rules
swiftmailer/swiftmailer               v6.0.2  Swiftmailer, free feature-rich PHP mailer
symfony/console                       v3.4.3  Symfony Console Component
symfony/css-selector                  v3.4.3  Symfony CssSelector Component
symfony/debug                         v3.4.3  Symfony Debug Component
symfony/event-dispatcher              v4.0.3  Symfony EventDispatcher Component

The only new package I added since last time is consoletvs/invoices.

I tried composer self-update, and I don't have any proxy or such things.

Here is my config:

  • Laravel 5.5
  • Composer 1.7.2
  • Tested on PHP 7.2 and PHP 7.1
  • Shared hosting (OVH)
  • IPv6 disabled
  • Firewall disabled

EDIT: composer diagnose results

$ ~/composer.phar diagnose

Checking composer.json: OK
Checking platform settings: WARNING
PHP was compiled with --enable-sigchild which can cause issues on some platforms.
Recompile it without this flag if possible, see also:
  https://bugs.php.net/bug.php?id=22999

Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
WARNING
Github has a rate limit on their API. You currently have 0 out of 60 requests left.
See https://developer.github.com/v3/#rate-limiting and also
    https://getcomposer.org/doc/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens
Checking disk free space: OK
Checking pubkeys:
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0  87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B  0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: OK
Composer version: 1.7.2
PHP version: 7.2.5
PHP binary path: /usr/local/php7.2/bin/php

EDIT: Add stack trace debug with -vvv(verbose)

$ ~/composer.phar update -vvv

Reading ./composer.json
Loading config file ./composer.json
Checked CA file /etc/ssl/certs/ca-certificates.crt: valid
Executing command (/home/user/www/dev): git branch --no-color --no-abbrev -v
Failed to initialize global composer: Composer could not find the config file: /homez.188/user/.composer/composer.json
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
Reading /home/user/www/dev/vendor/composer/installed.json
Loading plugin Symfony\Thanks\Thanks
Running 1.7.2 (2018-08-16 16:57:12) with PHP 7.1.17 on Linux / 4.14.61-ovh-vps-grsec-zfs-classid
Loading composer repositories with package information
Downloading https://larapack.io/packages.json
Downloading https://larapack.io/packages.json
Downloading https://larapack.io/packages.json


  [Composer\Downloader\TransportException]
  The "https://larapack.io/packages.json" file could not be downloaded: failed to open stream: Conn
  ection refused


Exception trace:
 () at phar:///home/user/composer.phar/src/Composer/Util/RemoteFilesystem.php:547
 Composer\Util\RemoteFilesystem->get() at phar:///home/user/composer.phar/src/Composer/Util/RemoteFilesystem.php:101
 Composer\Util\RemoteFilesystem->getContents() at phar:///home/user/composer.phar/src/Composer/Repository/ComposerRepository.php:682
 Composer\Repository\ComposerRepository->fetchFile() at phar:///home/user/composer.phar/src/Composer/Repository/ComposerRepository.php:497
 Composer\Repository\ComposerRepository->loadRootServerFile() at phar:///home/user/composer.phar/src/Composer/Repository/ComposerRepository.php:276
 Composer\Repository\ComposerRepository->hasProviders() at phar:///home/user/composer.phar/src/Composer/DependencyResolver/Pool.php:99
 Composer\DependencyResolver\Pool->addRepository() at phar:///home/user/composer.phar/src/Composer/Installer.php:378
 Composer\Installer->doInstall() at phar:///home/user/composer.phar/src/Composer/Installer.php:228
 Composer\Installer->run() at phar:///home/user/composer.phar/src/Composer/Command/UpdateCommand.php:162
 Composer\Command\UpdateCommand->execute() at phar:///home/user/composer.phar/vendor/symfony/console/Command/Command.php:241
 Symfony\Component\Console\Command\Command->run() at phar:///home/user/composer.phar/vendor/symfony/console/Application.php:843
 Symfony\Component\Console\Application->doRunCommand() at phar:///home/user/composer.phar/vendor/symfony/console/Application.php:193
 Symfony\Component\Console\Application->doRun() at phar:///home/user/composer.phar/src/Composer/Console/Application.php:254
 Composer\Console\Application->doRun() at phar:///home/user/composer.phar/vendor/symfony/console/Application.php:117
 Symfony\Component\Console\Application->run() at phar:///home/user/composer.phar/src/Composer/Console/Application.php:103
 Composer\Console\Application->run() at phar:///home/user/composer.phar/bin/composer:56
 require() at /home/user/composer.phar:24

update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [--with-dependencies] [--with-all-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [-i|--interactive] [--root-reqs] [--] [<packages>]...

EDIT

I've just tried $ curl https://larapack.io/packages.json

and I get : curl: (7) Failed to connect to larapack.io port 443: Connection refused

But if I do curl https://packagist.org/packages.json, it works.

Note that both files are accessible through my browser.

It gives me doubts about IPv6 being actually disabled...

I've tried several things, but I can't find a proper way to check if it disabled or not.

回答1:

I solved it doing composer install instead of composer update.

Still no idea about why it didn't work, but at least it works now...


For people trying (as I used to) to do composer update in a context of production, don't:

What are the differences between composer update and composer install?

When to install and when to update

  • composer update is mostly used in the 'development phase', to upgrade our project packages according to what we have specified in the composer.json file,

  • composer install is primarily used in the 'deploying phase' to install our application on a production server or on a testing environment, using the same dependencies stored in the composer.lock file created by composer update.

And a nice diagram here.


A discussion about curl error was posted here for reference: SSH Curl doesn't work when URL is accessible in browser

For french developers using SSH with a shared hosting pro at OVH, the support says external calls like curl are disabled in ssh, but obviously I could do curl https://packagist.org/packages.json. When they tried themselves, they got an error like action forbidden or something like that. It doesn't make any sense.