The requested PHP extension dom is missing from your system
When you encounter the error the requested PHP extension dom is missing from your system while running composer install, it usually means your PHP environment lacks the required extension, not that the Composer dependency resolver is broken. In the specific case of installing phpunit/php-code-coverage 4.0.8, this library explicitly requires the ext-dom extension to parse XML logs and generate coverage reports. The error message repeats because Composer's dependency solver hits a hard block: the required extension cannot be found in your loaded PHP modules, making the installation request unsatisfiable.
The most common source of confusion involves package naming on Debian-based systems like Ubuntu or Scotchbox Vagrant boxes. You might see suggestions to install php-xml. While this package often contains related libraries like SimpleXML and XML, it does not always include the full DOM extension, especially when dealing with older PHP versions or specific distribution repositories.
In your scenario, you attempted to resolve the issue by running:
sudo apt-get install php7.0-xml
This command likely installed a subset of XML libraries but left dom missing. To verify this, check which extensions are currently loaded in PHP before restarting Apache:
php -m | grep dom
If this returns nothing, the extension is indeed absent.
On Debian and Ubuntu systems, the package name for the DOM extension varies slightly depending on the PHP version string used in your repository configuration. If you are running PHP 7.0, the correct package is typically php7.0-dom. However, many modern tutorials assume a different major version or a more generic naming scheme.
Try installing the specific DOM module directly:
sudo apt-get install php7.0-dom
After installation, restart your web server to apply changes:
sudo service apache2 restart
# Or if using PHP-FPM directly
sudo service php7.0-fpm restart
Verify the fix by running the command again:
php -m | grep dom
You should now see dom listed in the output. Once confirmed, retry your Composer installation.
It is also worth noting that Scotchbox Vagrant boxes sometimes ship with slightly outdated package lists or PHP configurations. If installing php7.0-dom fails with a "package not found" error, you may need to update your package index first:
sudo apt-get update
sudo apt-get install php7.0-dom
Another potential pitfall occurs if your application is configured to use a specific PHP version via php-fpm or an SAPI that isn't automatically updated when system packages change. In such cases, restarting the service alone might not reload the new extension into the master process memory until a full restart occurs.
If you are developing locally within the Vagrant box and cannot modify system packages due to permission restrictions, consider using composer require --no-dev temporarily or switching to a version of PHPUnit that does not strictly require DOM if your test suite doesn't need code coverage. However, for production-ready workflows, ensuring the correct extension is loaded via the system package manager is the standard approach.
The key takeaway here is precision in package naming. Generic XML packages often group multiple extensions, but specific requirements like ext-dom demand the explicit installation of the corresponding module package. Always verify the exact PHP version string your distribution expects for that module before assuming a generic install will suffice.
