Installing ext-curl for PHP 7: A System-Level Approach
When upgrading from PHP 5 to PHP 7, one of the first friction points developers encounter is the change in how system extensions are packaged. In the PHP 5 era, particularly on RHEL-based distributions, you could simply run yum install php5-curl and have the extension immediately available. The naming convention made it intuitive, but that simplicity vanished with PHP 7.
If you installed PHP 7 using a repository like the one from Zend (now archived), your environment likely consists of standalone binaries rather than packages managed directly by the system package manager. This architectural shift means there is no single php7-curl or php-curl command that works universally out of the box. To resolve the ext-curl missing error during composer install, you must identify where your PHP installation lives and compile the extension specifically for that version.
The core issue lies in how Composer validates dependencies. When it encounters a package requiring ext-curl *, it checks the active PHP configuration via php -m. If curl is not listed, the validation fails immediately. This isn't just a missing file; it's a missing compiled library linked to your specific PHP binary.
To fix this on a Linux system where you installed PHP 7 manually or via a dedicated repo, you generally have three viable paths, each with different trade-offs regarding dependency management and isolation.
Option 1: Using Package Managers (If Available)
On distributions like Ubuntu or Debian, the package ecosystem has caught up to PHP 7. If your distribution offers php7.x-curl or a generic php-curl package that links against your installed PHP version, this is the preferred method.
You can attempt:
apt-get install php-curl
However, if you installed PHP 7 using a custom repository (like the archived Zend repo mentioned in similar scenarios), the system packages might conflict with your manual installation or provide an extension built for a different PHP version. In those cases, forcing the package manager to ignore existing files is risky and often leads to runtime errors where the wrong libphp.so gets loaded.
Option 2: Compiling from Source
This is the most reliable method when dealing with standalone PHP installations or older repositories that don't offer pre-compiled curl extensions. You need to download the source code for the matching PHP version (e.g., 7.0, 7.1, etc.) and compile the extension alongside your main PHP build.
The process involves downloading the php-curl source tarball from PECL or the official PHP releases:
wget https://pecl.php.net/get/curl-<version>.tgz
tar xzf curl-<version>.tgz
cd curl-<version>
You must then configure the build to point to your specific PHP installation headers and binary path. Use phpize located in your PHP 7 installation directory:
phpize
./configure --with-curl-dir=$(which-config curl) --with-php-config=$(which php)
make
sudo make install
After installation, the extension file (usually named curl.so) will appear in the extensions directory of your PHP config. You must ensure this file is listed in your php.ini. If you are running a custom CLI or FPM setup, verify that the correct php.ini is being used by checking with php -i | grep extension.
Option 3: Using PECL
For users who prefer a more streamlined approach without downloading raw source tarballs, PECL remains the standard tool for installing PHP extensions. You can install it directly via command line if your system has curl libraries (libcurl) installed:
pecl install curl
This method automatically compiles the extension against your system's headers and links it to your current PHP binary. Once installed, add extension=curl to your active php.ini. Remember that this requires a matching version of libcurl installed on the OS; if you are missing the system library, PECL will fail to configure.
Verification
Regardless of the method chosen, always verify the installation before running Composer again:
php -m | grep curl
If curl appears in the output, the extension is active. You can then retry your project setup:
composer install
A Note on Laravel and Modern PHP
While this guide addresses the legacy scenario of installing extensions for older PHP 7 versions using archived repositories, modern PHP development often utilizes newer versions (PHP 8.x) where these specific manual installation steps are less common due to better package ecosystem support. If you are building a new application with Laravel today, it is generally advisable to use a supported PHP version released within the last few years, as older PHP 7 branches have reached their End of Life and lack critical security updates. For production environments requiring legacy support or specific compatibility layers, ensure that your hosting environment or container image explicitly supports the required extensions; otherwise, relying on third-party repositories like LaravelCompany for managed infrastructure can sometimes simplify these configuration headaches by bundling necessary dependencies.
