6.

Composerのext-mbstring未有効エラーの対処法|php.ini設定

編集

エラー内容

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - laravel/framework v5.5.9 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - laravel/framework v5.5.8 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - laravel/framework v5.5.7 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    (以下、候補バージョンの数だけ同じ行が続く)

composer installcomposer create-project の実行時に出ます。同じ行が何十行も並ぶので驚きますが、原因は 1 つで、候補になったバージョンを 1 つずつ試して全部だめだった、という報告が並んでいるだけです。

このメッセージの読み方

Composer は「要求を満たす組み合わせが 1 つも作れなかった」ときにこのメッセージを出します。本当の原因は Problem ブロックの中に書かれています。

  1. Problem 1 の行だけを読む — 同じ内容が並んでいるなら原因は 1 つです。Problem 2 以降があれば原因は複数あります。
  2. -> の右側が結論 — 「何が足りないか」はここに書かれます。
  3. いちばん新しいバージョンの行を見る — 古いバージョンの行は「そちらでも駄目だった」という補足にすぎません。

よくある 4 つの原因

Problem 行の書かれ方 原因 対処
requires ext-xxx * -> the requested PHP extension xxx is missing PHP 拡張が入っていない PHP 拡張が無いときの対処
requires php ^8.1 -> your php version (8.0.x) does not satisfy that requirement PHP 本体のバージョンが要求を満たさない PHP を上げるか、要求の緩い版を指定する
conflicts with / don't satisfy が出る パッケージ同士のバージョン競合 片方の制約を緩める。composer why-not ベンダー名/パッケージ名 バージョン で理由が出る
requires ext-... だが本番では入っている CLI と Web で読む php.ini が違う php -mphp --ini で CLI 側を確認する

原因の切り分け

まずどのパッケージが何を要求しているかを確定させます。

# 入れたいバージョンが入らない理由を Composer に説明させる
composer why-not laravel/framework 10.0

# 今の環境が満たしているプラットフォーム要件を一覧する
composer show --platform

# 何が変わるかだけ見る(実際には入れない)
composer update --dry-run

composer why-not は「なぜそのバージョンにできないのか」を 1 行で返してくれるため、Problem ブロックを読むより早いことが多いです。

対処法(Linux)

上の例のように ext-mbstring が足りない場合は、拡張を入れて再実行します。

sudo apt install php-mbstring
sudo systemctl restart php8.2-fpm   # FPM を使っている場合
composer install

拡張の入れ方や、入れたのに認識されない場合の確認手順はthe requested PHP extension ... is missing from your systemに分けてまとめています。

--ignore-platform-reqs を使う前に

このオプションを付けるとプラットフォーム要件のチェックを飛ばしてインストールが通ります。ただし通るだけで、実行時に Call to undefined function mb_strlen() のような致命的エラーになります。

  • 使ってよい場面: CI でコードの静的解析だけしたい、といった実行しない用途
  • 使ってはいけない場面: 本番・開発サーバへのインストール。必ず拡張を入れて解決してください

関連記事

編集
Post Share
子ページ

子ページはありません

同階層のページ
  1. Fatal error: Maximum execution time of 30 seconds exceeded in...
  2. Fatal error: Uncaught Error: Cannot use object of type stdClass as array in ...
  3. Warning: Use of undefined constant ... - assumed '...' (this will throw an Error)
  4. ERROR: Call to undefined method Maatwebsite\Excel\Excel::load()
  5. Maximum execution time of 30 seconds exceeded
  6. Your requirements could not be resolved to an installable set of packages. ... To enable extensions, verify that they are enabled in your .ini files:
  7. could not find driver
  8. the requested PHP extension mbstring is missing from your system.
  9. the requested PHP extension dom is missing from your system.
  10. A non well formed numeric value encountered
  11. Warning: Cannot modify header information - headers already sent by ...
  12. php_network_getaddresses: getaddrinfo failed: Name or service not known
  13. XMLWriter::openUri(): Unable to resolve file path
  14. Object of class stdClass could not be converted to string
  15. Class 'Google_Service_Youtube' not found

最近更新/作成されたページ