The Missing ext-xml Error and How to Fix It
When attempting to bootstrap a new Symfony project, you might encounter an immediate blocker: Composer refuses to resolve dependencies because ext-xml is missing from your system. This specific error often appears when running php composer.phar create-project symfony/skeleton my-proj. The diagnostic output provided by Composer explicitly states that the requested PHP extension xml is missing, and it lists the relevant .ini files where the extension should be enabled or loaded.
In this scenario, you might have a version of the package installed, such as php-xml at version 1:7.1+55+ubuntu16.04.1+deb.sury.org+1, yet Composer still fails. This discrepancy usually indicates that while the library files exist on your system, they are not being loaded into the active PHP interpreter's memory space when running in CLI mode.
Checking the Active Configuration
Before making changes to configuration files, it is critical to verify which PHP configuration files are actually in use. The error message points to /etc/php/7.2/cli/php.ini and a series of directories under conf.d. However, simply searching for a line like extension=xml or ext-xml inside these files is often futile if the extension was never added there in the first place.
In many modern PHP distributions, particularly on Ubuntu and Debian-based systems, extensions are managed via separate packages rather than lines in the main .ini file. If you run php --ini and inspect the output, you will see the list of loaded configuration files. You should then check each of those specific files for an entry enabling the XML extension. If the line is commented out with a semicolon (e.g., ;extension=xml), uncommenting it might resolve the issue if the extension name matches exactly what the system expects.
Installing the Correct Package
If no configuration file contains the necessary directive, the most direct solution is to install the missing package using your system's package manager. In the provided logs, the user attempted sudo apt-get install php-xml but received a message stating the package was already the newest. This is a common point of confusion. The version string 1:7.1+... suggests the package was compiled for PHP 7.1, while your active interpreter is running PHP 7.2 (PHP 7.2.0-2...).
Package managers on Linux often use major versioning in their filenames or build IDs. If you have PHP 7.2 installed but only the PHP 7.1 php-xml package, they are incompatible. To fix this, you must ensure you install the extension that matches your specific PHP minor version. On Ubuntu systems, this usually involves running:
sudo apt-get update
sudo apt-get install php7.2-xml
Note the specific version suffix in the package name. If php7.2-xml is not available on your repository, you may need to check for php-xml specifically built against PHP 7.2, or consider using a PPA (Personal Package Archive) that provides up-to-date extensions for newer PHP versions.
Why You Don't Need to Uncomment ext-xml
It is important to address the misconception regarding finding ext-xml in the .ini files. In modern PHP builds, you will rarely see a line explicitly named ext-xml. The directive is almost always just extension=xml. Furthermore, if you are using a distribution-based installation like Ubuntu, enabling extensions is frequently handled entirely by installing the corresponding Debian package rather than editing configuration files manually.
Manually editing .ini files can lead to conflicts, especially when switching between PHP versions or updating packages. The cleanest approach is to ensure your php.ini contains extension=xml (if not already there) and that the matching binary package is installed. If you are using a shared hosting environment where you cannot install system packages, the solution might involve contacting the host to enable the extension via their control panel or upgrading your PHP version if supported.
For Laravel developers specifically, this issue can also arise when switching between different PHP versions for CLI and Web environments. Ensure that both php -m in your CLI environment and the web server (e.g., PHP-FPM) show xml in the list of loaded modules. If they differ, it will cause fatal errors or unexpected behavior during development.