Can't install package via composer: PHP extension zip is missing
When you attempt to run composer global require "laravel/installer" on an Ubuntu system and encounter a resolution failure, the root cause is almost invariably a missing or disabled PHP extension. The error message explicitly states that ext-zip is missing from your system. This isn't just a generic dependency issue; it is a hard requirement for the Laravel installer to function correctly. Without this extension, Composer cannot satisfy the version constraints defined in composer.json files, leading to the specific "Your requirements could not be resolved to an installable set of packages" error you are seeing.
The error output provides a map of where PHP looks for configuration directives. It lists several .ini files located in /etc/php/7.0/cli/conf.d/. While the message suggests verifying that extensions are enabled, it does not explicitly state how to enable them if they are currently absent from the system's package repository. This distinction is crucial. An extension can be "not loaded" because the PHP binary was compiled without it, or it can be "not loaded" because the .ini file exists but lacks an extension=zip directive.
On Ubuntu and Debian-based distributions, the solution usually involves installing the development package that contains the extension source code. The specific command to resolve this on your current system is:
sudo apt-get update
sudo apt-get install php7.0-zip
Once installed, you must ensure the extension is actually loaded. You can do this by checking the active configuration files again using php --ini. If the extension=zip directive is missing from the file listed for CLI mode (typically /etc/php/7.0/cli/php.ini or a file within the conf.d directory), you may need to create or edit that file to add the line:
extension=zip
After making changes to the .ini files, restart your shell session or run PHP again to ensure the new configuration is picked up. You can verify the installation was successful by running:
php -m | grep zip
If this command returns zip, the extension is active. You should then retry your original command:
composer global require "laravel/installer"
There is a notable trade-off in how you approach enabling extensions depending on your deployment strategy. In a production environment, manually editing .ini files is often discouraged because it can lead to conflicts when switching between PHP versions or when deploying updates via package managers. A more robust approach for production servers is to use the php.ini file generated by the package manager or to utilize Swoole or OPcache configuration tools that handle extension loading dynamically. However, for local development environments like your Ubuntu PC, direct installation and manual verification of .ini files remain the standard and most reliable method.
It is also worth noting that the error log indicates you are running PHP 7.0. This version has reached its end-of-life status. While fixing the zip extension issue will resolve your immediate problem, continuing to use PHP 7.0 exposes your project to known security vulnerabilities. Consider upgrading to a supported Long-Term Support (LTS) version of PHP, such as 8.1 or later, which is compatible with modern Laravel versions and includes built-in improvements for performance and security. Upgrading often comes with its own set of dependency adjustments, but the zip extension remains a critical component regardless of the PHP version you choose.
If you are following a tutorial that assumes a pre-configured environment, remember that "out of the box" setups on Linux distributions rarely include every possible extension by default. Always verify your installed extensions against the requirements listed in the Composer error output before assuming a configuration failure is solely due to missing packages.
