8.

the requested PHP extension mbstring is missing from your system 対処

編集

エラー内容

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

要求された PHP 拡張がインストールされていない、という意味です。mbstring の部分は環境によって xml / curl / zip / gd などに変わります。

行が何十行も並ぶ理由や、拡張以外が原因のときの読み方はYour requirements could not be resolved to an installable set of packagesにまとめています。

発生条件/原因

  • composer install / composer create-project の実行時
  • PHP はインストールされているが、拡張パッケージが別売りになっているディストリビューション(Debian / Ubuntu / RHEL 系はこの形)
  • 複数の PHP バージョンが同居していて、Composer が使う CLI の PHP と、拡張を入れた PHP が違う

よく要求される拡張

拡張 用途 Debian / Ubuntu のパッケージ名
mbstringマルチバイト文字列。日本語を扱うなら実質必須php-mbstring
xml / domXML 解析。テストやテンプレートで使われるphp-xml
curlHTTP クライアントphp-curl
zipComposer がパッケージを展開するのに使うphp-zip
gd / imagick画像処理php-gd / php-imagick
intl国際化(日付・数値の書式)php-intl
bcmath任意精度計算php-bcmath

対処法(Linux)

足りない拡張を入れて、Composer をやり直します。

sudo apt install php-mbstring
composer install

上記で直らない場合、パッケージ一覧が古いことがあります。

sudo apt update
sudo apt upgrade

RHEL / Rocky Linux 系なら sudo dnf install php-mbstring、macOS の Homebrew なら通常 PHP 本体に同梱されています。

入れたのに認識されないとき

Composer は CLI の PHP を使います。ブラウザ(Web サーバ)側の phpinfo() で拡張が見えていても、CLI 側に入っていなければこのエラーは消えません。

# CLI が読み込んでいる拡張の一覧
php -m | grep mbstring

# CLI が読んでいる php.ini の場所
php --ini

# CLI の PHP のバージョン(複数入っているとここがずれる)
php -v
which php

確認するポイントは次の 3 つです。

  1. php -m に出るか — 出なければ CLI 側に入っていません
  2. php --ini が指す ini に extension=mbstring があるか — CLI と FPM で ini が別なのはよくあります
  3. php -v のバージョンと、入れたパッケージのバージョンが一致するかphp8.1-mbstring を入れたのに CLI が 8.2 なら効きません

PHP-FPM を使っている場合、拡張を入れた後は sudo systemctl restart php8.2-fpm で再起動が要ります(Composer だけなら再起動は不要です)。

関連記事

編集
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