PHP

【PHP】composer require 時に「Your requirements could not be resolved to an installable set of packages.」とエラーとなった時の対応!

こんにちは、あきぞらです。

DockerPHPComposerをいれて検証をしようと思っていたところ、

composer requireを実行したときに、エラーが返ってきてしまいました。

これについて対応方法を書いていきたいと思います。

環境

実行したときの環境はこちらです。

  • Windows10 HOME
  • Docker Quickstar Terminal
  • Ubuntu 20.04
  • PHP、Composerは導入済

「composer require」した時のエラー

出力されたエラーはこちらです。

phpspreadsheetをインストールしようとしていました。

$ composer require phpoffice/phpspreadsheet
Using version ^1.12 for phpoffice/phpspreadsheet
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for phpoffice/phpspreadsheet ^1.12 -> satisfiable by phpoffice/phpspreadsheet[1.12.0].
    - phpoffice/phpspreadsheet 1.12.0 requires ext-dom * -> the requested PHP extension dom is missing from your system.

  To enable extensions, verify that they are enabled in your .ini files:
    - /etc/php/7.4/cli/php.ini


...(省略)...

エラー内容を見ると、「Problem1」のところに、requires ext-domとありますね。

「PHP extension dom」というのが必要そうです。

必要な拡張モジュールをインストール

PHPマニュアルのこちらのページを参照すると、

こちらを実行してインストールできそうです。

今回はUbuntuなのでこちらを実行します。

$ sudo apt-get install php7.4-xml
........
Problem 1
    - Installation request for phpoffice/phpspreadsheet ^1.12 -> satisfiable by phpoffice/phpspreadsheet[1.12.0].
    - phpoffice/phpspreadsheet 1.12.0 requires ext-gd * -> the requested PHP extension gd is missing from your system.
........

再度composer requireを実行してみますが、

再度似たようなエラーがでます。

今度は、「requires ext-gd」とあります。

こちらもインストールしていきます。

$ sudo apt-get install php7.4-gd

エラー文を確認しながら必要な拡張モジュールをインストール

必要な拡張モジュールが全てインストールできるまで繰り返します。

これも実行して、やっとcomposer requireが通りました。

今回インストールが必要だったものはこちらです。

  • php7.4-xml
  • php7.4-gd
  • php7.4-mbstring

以下を実行した形になります。

$ sudo apt-get install php7.4-gd
$ sudo apt-get install php7.4-xml
$ sudo apt-get install php7.4-mgstring

結論とまとめ

エラーを読みながら必要な拡張モジュールを入れていきましょう。

必要なものは一気に見せてくれれば良いんですけどね…。

では、また!

-PHP
-

Copyright© あきぞらてっく , 2025 All Rights Reserved Powered by AFFINGER5.