Composer でライブラリをインストールした際に Cloning failed using an ssh ... が出たときの対応内容

はじめに

Docker の PHP 公式イメージを使ったコンテナ内で、composer create-project を使って CakePHP 4 のインストールを試みた際に、下記のように Cloning failed using an ssh for authentication のエラーが出ました。

# php composer.phar create-project --prefer-dist cakephp/app my-project
...
Failed to download cakephp/app from dist: The zip extension and unzip command are both missing, skipping.
Your command-line PHP is using multiple ini files. Run `php --ini` to show them.
...
Cloning failed using an ssh key for authentication, enter your GitHub credentials to access private repos
...

対応内容

注目すべきは、メッセージ前半にある The zip extension and unzip command are both missing の部分です。

これによると問題は、 PHP の zip 拡張 と unzip コマンド の両方がないことのようです。

もしこのメッセージがない場合は、他にヒントになりそうな文言がないか、エラーメッセージ全体を再度確認してみると良いかもしれません。

今回は Docker の PHP 公式イメージを使っていたので(=OS が Debian なので)下記コマンドで unzip をインストールしたところ解決しました。

# apt-get install -y unzip

PHP の zip 拡張だけを入れた状態でも試したところ、解決はしたのですが、下記メッセージが出たので unzip の方を解決策としてご紹介しました。

As there is no 'unzip' command installed zip files are being unpacked using the PHP zip extension.
This may cause invalid reports of corrupted archives. Besides, any UNIX permissions (e.g. executable) defined in the archives will be lost.Installing 'unzip' may remediate them.