PHP - Composer(パッケージ管理) - トラブルシュート


クラウディア 


1. 概要
2. 診断
3. ネットワーク

1. 概要

 「composer」のコマンドがエラーになることがあります。  いろいろ原因は、あるようで、「IPv6」はだめだけど「IPv4」ならいける場合は、「IPv4」の優先度をあげるとか、「IPv6」を無効にするだとかあるようで。

2. 診断

 「diagnose」(診断)します。  「fcitx」にも同じようなコマンドがありますな。  とりあえず、まず、おおまかにつかむために、下記のコマンドを流します。

composer diagnose
 正常な場合は、大体。

Checking composer.json: WARNING
No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.
Checking platform settings: OK
Checking git settings: OK git version 2.43.0
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys: FAIL
Missing pubkey for tags verification
Missing pubkey for dev verification
Run composer self-update --update-keys to set them up
Checking composer version: OK
Composer version: 2.6.6
PHP version: 8.0.30
PHP binary path: /usr/local/bin/php
OpenSSL version: OpenSSL 1.1.1v  1 Aug 2023
cURL version: 8.5.0 libz 1.2.13 ssl OpenSSL/3.0.12
zip: extension not loaded, unzip present, 7-Zip not available
 てな感じで出力されます。  「Checking composer.json:」の「WARNING」は、説明にもあるように「『プロプライエタリソフトウェア』じゃなきゃ、問題ではありませんよ」と言っているので、フリーの素材しか使わないのであれば、気にしなくてもいいのです。  「Checking pubkeys:」の「FAIL」も、別にキーを必要なものがなければ問題ありません。

3. ネットワーク

 2023年12月22日、こんなことがありました。  結果が。

Checking platform settings: OK
Checking git settings: OK git version 2.43.0
Checking http connectivity to packagist: A connection timeout was encountered. If you intend to run Composer without connecting to the internet, run the command again prefixed with COMPOSER_DISABLE_NETWORK=1 to make Composer run in offline mode.
FAIL
The following exception probably indicates you have misconfigured DNS resolver(s)
[Composer\Downloader\TransportException] curl error 28 while downloading http://repo.packagist.org/packages.json: Resolving timed out after 10013 milliseconds
Checking https connectivity to packagist: OK
Checking github.com rate limit: FAIL
[Composer\Downloader\TransportException] curl error 28 while downloading https://api.github.com/rate_limit: Resolving timed out after 10009 milliseconds
Checking disk free space: OK
Checking pubkeys: FAIL
Missing pubkey for tags verification
Missing pubkey for dev verification
Run composer self-update --update-keys to set them up
Checking composer version: FAIL
[Composer\Downloader\TransportException] curl error 28 while downloading https://getcomposer.org/versions: Resolving timed out after 10015 milliseconds
Composer version: 2.6.6
PHP version: 8.2.13
PHP binary path: /usr/local/bin/php
OpenSSL version: OpenSSL 3.0.12 24 Oct 2023
cURL version: 8.5.0 libz 1.3 ssl OpenSSL/3.0.12
zip: extension not loaded, unzip present, 7-Zip not available
 てな、感じで。  「Checking http connectivity to packagist:」のタイムアウトをはじめ、ネットワーク的にだめなようなのです。  あれこれ、調べた挙句・・・。  今回(2023年12月22日)の場合は。

/etc/resolv.conf
 だったのです。  新規にインストールしたマシンで、インストール時に作成されたファイルのままにしていました。  これでも、「ports」のインストールなんぞが通るので、気にしていなかったのですが・・・。  外部へ出ていくときに、見つけられないことがあるようです。  「DHCP」を使って、自動で設定した場合、ルータのアドレスになっていることが覆うのですが。  プロバイダから提供された、「DNS」サーバがあれば、そのアドレスを使用することをお勧めしますし。  もし自前でキャッシュサーバ(「unbound」のような)を立ち上げている場合、プロバイダから提供されたものより、自分のキャッシュサーバを前に持ってきた方が速かったりします。

AbemaTV 無料体験