PR

【Laravel】 composer で Failed to connect to repo.packagist.org port 443 エラー

trouble-shoot03 Laravel
この記事は約5分で読めます。
記事内に広告が含まれています。

この記事では、 Laravel のセットアップ時の composer create-project コマンド実行をすると curl error 7 while downloading https://repo.packagist.org/p2/laravel/framework.json: Failed to connect to repo.packagist.org port 443 after 3123 ms: Couldn't connect to server というエラーに直面した時の対処法を記載します。

PHP で開発を行うときは、 Laravel を用いることがかなり多いと思います。

一度開発環境をセットアップしてしまえば、そのあとはあまり困らないと思うのですが、最初につまづくと初心者の場合はなかなか苦労すると思います。

この記事が一つのトラブルシューティングの備忘録になれば幸いです。

エラーの原因

curl error 7 while downloading https://repo.packagist.org/p2/laravel/framework.json: Failed to connect to repo.packagist.org port 443 after 3123 ms: Couldn't connect to server

このエラーは、 laravel のリポジトリにつながりませんでしたと言っていますね。

ではその原因を探るべく、以下のコマンドを実行します。

composer diagnose

これはエラー時の診断コマンドのようなもので、原因の特定に役立ちます。

スポンサーリンク
Checking platform settings: OK
Checking git settings: OK git version 2.37.3
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
Checking Composer and its dependencies for vulnerabilities: OK
Composer version: 2.7.7
PHP version: 8.3.8
PHP binary path: /usr/local/Cellar/php/8.3.8/bin/php
OpenSSL version: OpenSSL 3.3.1 4 Jun 2024
curl version: 8.8.0 libz 1.2.12 ssl (SecureTransport) OpenSSL/3.3.1
zip: extension present, unzip present, 7-Zip not available

原因が見えてきました。

Checking pubkeys: FAIL と記載があるので、公開鍵の設定が必要そうです。

公開鍵(Public Key)の設定

Run composer self-update --update-keys to set them up と指示があるので、実行します。

composer self-update --update-keys

すると、以下のように 公開鍵(Public Key) の設定を求められます。

Open https://composer.github.io/pubkeys.html to find the latest keys
Enter Dev / Snapshot Public Key (including lines with -----):

composer の公式の GitHub に記載があるので、ここの値を設定します。

https://composer.github.io/pubkeys.html
スポンサーリンク
Enter Tags Public Key (including lines with -----):

タグの設定も求められます。

同じページ下段に記載があるので、これも設定しましょう。

composer diagnose

Checking platform settings: OK
Checking git settings: OK git version 2.37.3
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: 
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
Checking Composer and its dependencies for vulnerabilities: OK
Composer version: 2.7.7
PHP version: 8.3.8
PHP binary path: /usr/local/Cellar/php/8.3.8/bin/php
OpenSSL version: OpenSSL 3.3.1 4 Jun 2024
curl version: 8.8.0 libz 1.2.12 ssl (SecureTransport) OpenSSL/3.3.1

再実行で ALL OK になりました。

スポンサーリンク

おわりに

このようなトラブルシューティングは慣れていれば 「ああ、エラーね」 ですぐに調査に移れるのですが、最初は戸惑いますね。

この備忘録が役立ちますように。

コメント

タイトルとURLをコピーしました