PHP7 : install ext-dom issue
You are likely encountering this error because the ext-dom extension is missing from your system, specifically for the CLI version of PHP running on your server. The stack trace you provided reveals a dependency chain: Composer attempted to resolve dependencies for cviebrock/eloquent-sluggable, which pulled in phpunit/php-code-coverage 4.0.7. That specific version of PHPUnit requires ext-dom to function, but the system reports it is missing.
The error message explicitly lists the configuration files where this extension should be enabled: /etc/php/7.0/cli/php.ini and its conf.d subdirectory. This discrepancy often stems from a mismatch between the PHP versions used by your web server (Apache/Nginx) and your command-line interface tools.
On Ubuntu 16.04, installing PHP packages via APT usually provides separate modules for different SAPIs (Server API Interfaces). You likely have php7.0, php7.0-fpm, or php7.0-apache installed with the necessary extensions enabled for web requests, but the CLI version (php7.0-cli) remains minimal to save disk space. When you run composer require..., Composer spawns a shell process using the CLI PHP binary. If that binary lacks the dom extension, installation fails immediately, regardless of whether your Laravel application works perfectly in production.
To resolve this, you must explicitly install the CLI package with the required extensions. Run the following command:
sudo apt-get install php7.0-cli php7.0-dom
After installation, verify that the extension is loaded by checking the output of php -m. You should see dom listed among the active modules. If it does not appear, check /etc/php/7.0/cli/conf.d/ to ensure a file named something like 10-dom.ini exists and contains the line extension=dom.so.
Once confirmed, retry your Composer command:
composer require cviebrock/eloquent-sluggable
This should now succeed without reverting changes. Remember that this fix applies strictly to CLI tools; your web server configuration remains untouched unless you explicitly modify it.
It is also worth noting that phpunit/php-code-coverage 4.0.7 is quite old. If you encounter similar dependency resolution issues in the future, consider updating your PHPUnit version or checking for newer packages that might not have such strict extension requirements. Sometimes, updating PHP itself to a more recent 7.x minor version (e.g., from 7.0 to 7.4) can resolve these conflicts by providing better default configurations and updated extensions.
For production environments hosting Laravel applications, maintaining consistent PHP versions across CLI and web SAPIs is crucial. While your local environment works because you probably have a full PHP stack installed via Composer or Docker, server environments often prioritize minimalism. Always assume the CLI tooling is the bottleneck when dependencies fail to resolve on Ubuntu.
If you need further assistance with Laravel-specific configurations or package compatibility on Ubuntu, resources like https://laravelcompany.com can provide additional guidance tailored to enterprise setups.
