laravel9 環境構築時にエラー「Root composer.json requires phpunit/phpunit」が発生した場合の対処法

laravel9 環境構築時にエラー「Root composer.json requires phpunit/phpunit」が発生した場合の対処法

laravel9の環境構築時に、エラー「Root composer.json requires phpunit/phpunit」が発生した場合の対処法を記述してます。

環境

  • OS  Ubuntu 21.10
  • php 8.1.2
  • composer 2.2.6

エラー全文

プロジェクト作成時に発生。

$ composer create-project laravel/laravel

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

  Problem 1
    - Root composer.json requires phpunit/phpunit ^9.5.10 -> satisfiable by phpunit/phpunit[9.5.10, ..., 9.5.x-dev].    - phpunit/phpunit[9.5.10, ..., 9.5.x-dev] require ext-dom * -> it is missing from your system. Install or enable PHP's dom extension.

  Problem 2
    - laravel/framework[v9.0.0-beta.1, ..., 9.x-dev] require tijsverkoyen/css-to-inline-styles ^2.2.2 -> satisfiable by tijsverkoyen/css-to-inline-styles[2.2.2, 2.2.3, 2.2.4, 2.2.x-dev].
    - tijsverkoyen/css-to-inline-styles 2.2.2 requires php ^5.5 || ^7.0 -> your php version (8.1.2) does not satisfy that requirement.
    - tijsverkoyen/css-to-inline-styles[2.2.3, ..., 2.2.x-dev] require ext-dom * -> it is missing from your system. Install or enable PHP's dom extension.
    - Root composer.json requires laravel/framework ^9.0 -> satisfiable by laravel/framework[v9.0.0-beta.1, ..., 9.x-dev].

原因

php-xmlをインストールしていなかったため

対処法

インストールを実行する。zipも一緒にインストールしました。

$ sudo apt install php8.1-{xml,zip}