[composer]エラー「the requested PHP extension zip is missing from your system.」が大量発生!解決策

[composer]エラー「the requested PHP extension zip is missing from your system.」が大量発生!解決策
2021年05月08日2023年10月10日

ComposerでLaravelのパッケージをインストールしようとしたら大量のエラー「the requested PHP extension zip is missing from your system.」が発生しました。

やりたかったこと

CSVアップロードのパッケージをインストールしたかったのですが、エラーでインストールができない。

$ composer require maatwebsite/excel
Warning from https://repo.packagist.org: You are using an outdated version of Composer. Composer 2 is now available and you should upgrade. See https://getcomposer.org/2
Using version ^3.1 for maatwebsite/excel
./composer.json has been created
Loading composer repositories with package information
Warning from https://repo.packagist.org: You are using an outdated version of Composer. Composer 2 is now available and you should upgrade. See https://getcomposer.org/2
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

~省略~

    - phpoffice/phpspreadsheet 1.10.1 requires ext-zip * -> the requested PHP extension zip is missing from your system.
    - phpoffice/phpspreadsheet 1.10.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.
    - Installation request for maatwebsite/excel ^3.1 -> satisfiable by maatwebsite/excel[3.1.0, 3.1.1, 3.1.10, 3.1.11, 3.1.12, 3.1.13, 3.1.14, 3.1.15, 3.1.16, 3.1.17, 3.1.18, 3.1.19, 3.1.2, 3.1.20, 3.1.21, 3.1.22, 3.1.23, 3.1.24, 3.1.25, 3.1.26, 3.1.27, 3.1.28, 3.1.29, 3.1.3, 3.1.30, 3.1.4, 3.1.5, 3.1.6, 3.1.7, 3.1.8, 3.1.9].

  To enable extensions, verify that they are enabled in your .ini files:

~省略~
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

Installation failed, deleting ./composer.json.

エラーの内容を翻訳してみると「要求されたPHP拡張zipがシステムにありません」というエラーのようです。

PHPの拡張ライブラリ「zip」がないよ~と言っているので、PHPのライブラリを確認してみます。

php --ri zip
Extension 'zip' not present.

確かにzipが無いようです。

エラーの解決方法

エラー内容にしたがってzipのライブラリをインストールします。

// PHPのバージョンを確認
$ php -v
PHP 7.4.16 (cli) (built: Mar  2 2021 10:35:17) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies


// 「php-pecl-zip」をインストール
$ sudo yum -y install --enablerepo=remi,remi-php74 php-pecl-zip

インストール後、「php-pecl-zip」が動作しているか確認します。

$ php --ri zip

zip

Zip => enabled
Zip version => 1.19.2
Libzip version => 1.7.3
BZIP2 compression => Yes
XZ compression => Yes
ZSTD compression => No
AES-128 encryption => Yes
AES-192 encryption => Yes
AES-256 encryption => Yes

「Extension 'zip' not present.」から上記のログが出力されていれば問題なくインストール完了です。

エラーになったcomposer installを再実行

composer installを再実行します。

$ composer require maatwebsite/excel
~省略~
Writing lock file
Generating autoload files
10 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

無事インストール環境です。

本番環境も同様のエラーが発生する可能性があるので、デプロイする際は「php-pecl-zip」がインストールされているか確認ししたほうが良いかもしれないです。

あまり使わないライブラリなので!たぶん。。。

コメント

コメントを残す

お名前(任意)
コメント:新規