composerでlaravelを導入しようとして発生したエラー「ext-mbstring」「ext-dom」

どうもやまうちです。

普段自宅でlaravelの環境をつくるときはlaradockを使っていたのですが、楽々構築したいなあと思い
「composerで構築しよう！」
と思い立ち構築したときに発生したエラーと、対処法です。

発生したエラーはタイトルにある通り、`ext-mbstrin`と`ext-dom`この2つです。

composerのダウンロードはここから
https://getcomposer.org/

## 環境
- windows 10 pro 
- WSL

## プロジェクトを作成
まずはこのコマンドでプロジェクトの作成をしました。

```
composer create-project laravel/laravel project-name --prefer-dist
```
※project-nameは任意のプロジェクト名です
このコマンドを実行するとプロジェクトが作成できます。

非常に簡単ですね＼(^o^)／

## ext-mbstringのエラー発生
しかしさきほどのコマンドを実施するとこのようなエラーが発生しました。

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

  Problem 1
    - laravel/framework v6.9.0 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - laravel/framework v6.8.0 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - laravel/framework v6.7.0 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - laravel/framework v6.6.2 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - laravel/framework v6.6.1 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - laravel/framework v6.6.0 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - laravel/framework v6.5.2 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - laravel/framework v6.5.1 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - laravel/framework v6.5.0 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - laravel/framework v6.4.1 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - laravel/framework v6.4.0 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - laravel/framework v6.3.0 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - laravel/framework v6.2.0 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - laravel/framework 6.x-dev requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - Installation request for laravel/framework ^6.2 -> satisfiable by laravel/framework[6.x-dev, v6.2.0, v6.3.0, v6.4.0, v6.4.1, v6.5.0, v6.5.1, v6.5.2, v6.6.0, v6.6.1, v6.6.2, v6.7.0, v6.8.0, v6.9.0].

```

なんか色々たくさん書いてありますが、ここに注目。
`requires ext-mbstring`
`the requested PHP extension mbstring is missing from your system`
グーグル先生になんて言っているのか聞いたところ、「mbstringという拡張機能がないよ！」って話でした。
じゃあそれを導入すれば良いでしょう。

## mbstringを導入

```
sudo apt-get install php7.2-mbstring
```
こいつを実行しました。
僕はWSL(Ubuntu)なので上記コマンドを実行しました。
CentOSとかだと

```
sudo yum install --enablerepo=remi-php72 php-mbstring php-openssl php-xml unzip
```
これでいけるらしいです。

これでmbstringを導入できましたので、一度さきほど作成したプロジェクトフォルダを削除して、もう一度下記を実行。

```
composer create-project laravel/laravel project-name --prefer-dist
```

## ext-domのエラー発生
次はこんなエラーが発生しました。

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

  Problem 1
    - phpunit/phpunit 8.5.x-dev requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.5.1 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.5.0 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.4.3 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.4.2 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.4.1 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.4.0 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.3.5 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.3.4 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.3.3 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.3.2 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.3.1 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.3.0 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.2.5 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.2.4 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.2.3 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.2.2 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.2.1 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.2.0 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.1.6 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.1.5 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.1.4 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.1.3 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.1.2 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.1.1 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.1.0 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.0.6 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.0.5 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.0.4 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.0.3 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.0.2 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.0.1 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 8.0.0 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - Installation request for phpunit/phpunit ^8.0 -> satisfiable by phpunit/phpunit[8.0.0, 8.0.1, 8.0.2, 8.0.3, 8.0.4, 8.0.5, 8.0.6, 8.1.0, 8.1.1, 8.1.2, 8.1.3, 8.1.4, 8.1.5, 8.1.6, 8.2.0, 8.2.1, 8.2.2, 8.2.3, 8.2.4, 8.2.5, 8.3.0, 8.3.1, 8.3.2, 8.3.3, 8.3.4, 8.3.5, 8.4.0, 8.4.1, 8.4.2, 8.4.3, 8.5.0, 8.5.1, 8.5.x-dev].

```

今回見るべきはここ
`requires ext-dom`
`the requested PHP extension dom is missing from your system`
書いていることは先程のエラーとほとんど一緒です。
domを導入したら大丈夫そうです。

## domを導入

```
sudo apt-get install php7.2-dom
```
上記はUbuntu。
CentOSはこれでできるらしい。

```
sudo yum install php-xml
```

もう一度プロジェクトフォルダを削除して、下記を実行。

```
composer create-project laravel/laravel project-name --prefer-dist
```

## プロジェクトの作成成功

```
Application key set successfully
```
この文字が無事見れたので完了です。
環境構築って難しい。。。