When you attempt to scaffold a new Laravel project on WSL2 Ubuntu using composer create-project, you might encounter the error: Your requirements could not be resolved to an installable set of packages. This is particularly common when running as root or when the default system PHP distribution lacks specific extensions required by modern Laravel dependencies.
The error log explicitly points to two missing extensions: ext-xml and ext-dom. Laravel 9.x, specifically version 9.3.5 in this instance, requires laravel/pint for code styling and phpunit/phpunit for testing. Both of these packages have hard dependencies on the XML parsing libraries (libxml and dom). If your system PHP installation does not load these extensions, Composer cannot resolve the dependency graph, and the installation halts.
While the error message suggests running Composer with flags like --ignore-platform-req=ext-xml, this is a temporary workaround that bypasses critical requirements. It is better to fix the underlying environment. First, ensure you are not running as root. The log warns against executing Composer as root/super user, so stop if prompted and use your regular user account.
To resolve the missing extensions permanently, you need to enable them in your PHP configuration. In Ubuntu's default PHP 8.1 stack, these modules often exist but are commented out in the cli.ini files or simply not installed as development packages.
You can check which .ini files are currently active by running:
php --ini
Once you identify the configuration path (typically /etc/php/8.1/cli/conf.d/), you can enable the extensions. For Ubuntu systems using apt, it is often cleaner to install the development packages that provide these libraries rather than manually editing .ini files every time:
sudo apt-get update
sudo apt-get install php-xml php-dom
After installing the packages, ensure the extensions are actually loaded. You can verify this by running:
php -m | grep xml
php -m | grep dom
If the modules appear in the list but you still face issues, manually uncommenting them in the configuration files might be necessary. Locate the 20-xml.ini and 20-dom.ini (or similar) files within your conf.d directory and ensure the lines starting with ;extension= are changed to extension= without the semicolon.
Once the extensions are active, retry the project creation. The error should disappear, and Composer will proceed to install Laravel 9.3.5 along with its dependencies like Pint and PHPUnit. If you are working in a shared hosting environment or a specific WSL setup where package installation is restricted, you may need to adjust your PHP version via add-apt-repository ppa:ondrej/php to access versions that come pre-configured with these extensions enabled by default.