執行 composer 時出現 requires ext-curl / ext-dom / ext-simplexml 的解決辦法

系統剛安裝好 PHP,首次執行 composer install 時有可能會出現類似這樣的錯誤:

Problem 1
  - tijsverkoyen/css-to-inline-styles is locked to version 2.2.4 and an update of this package was not requested.
  - tijsverkoyen/css-to-inline-styles 2.2.4 requires ext-dom * -> it is missing from your system. Install or enable PHP's dom extension.
Problem 2
  - phar-io/manifest is locked to version 2.0.3 and an update of this package was not requested.
  - phar-io/manifest 2.0.3 requires ext-dom * -> it is missing from your system. Install or enable PHP's dom extension.
Problem 3
  - phpunit/php-code-coverage is locked to version 7.0.15 and an update of this package was not requested.
  - phpunit/php-code-coverage 7.0.15 requires ext-dom * -> it is missing from your system. Install or enable PHP's dom extension.
Problem 4
  - phpunit/phpunit is locked to version 8.5.26 and an update of this package was not requested.
  - phpunit/phpunit 8.5.26 requires ext-dom * -> it is missing from your system. Install or enable PHP's dom extension.
Problem 5
  - squizlabs/php_codesniffer is locked to version 3.6.2 and an update of this package was not requested.
  - squizlabs/php_codesniffer 3.6.2 requires ext-simplexml * -> it is missing from your system. Install or enable PHP's simplexml extension.

原因是透過 ppa:ondrej/php 安裝的 PHP 預設安裝的擴充套件較少(對一些人來說這樣比較乾淨)。

如果看到的是缺乏 ext-curl,可以這樣安裝:

sudo apt isntall php-curl

如果看到的是缺乏 ext-domext-simplexml,可以這樣安裝:

sudo apt install php-xml

有些時候也可能會缺乏 mbstring,一樣可以透過 apt 安裝:

sudo apt install php-mbstring