Call to undefined function curl_init() even it is enabled in php7

Call to undefined function curl_init() even it is enabled in php7

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Call to undefined function curl_init() even it is enabled in php7

Encountering a Call to undefined function curl_init() error after installing PHP 7 on Ubuntu can be genuinely confusing, especially when the phpinfo() page clearly indicates that the cURL extension is loaded. It feels contradictory: how can the extension exist if the code refuses to call its functions? The issue isn't typically a missing DLL or a bad build; it almost always stems from a mismatch between how your application invokes PHP and how the PHP interpreter is actually running the script.

When you execute phpinfo() in a browser, you are seeing the output of the PHP process that handles web requests. However, when you run php -i | grep curl in the terminal, you are inspecting the CLI (Command Line Interface) environment. In many Ubuntu installations, these two environments are managed by separate binary paths and configuration directories. The source material notes that phpinfo() confirms cURL is enabled, yet the terminal command reveals a configuration file at /etc/php/7.0/cli/conf.d/20-curl.ini. This specific path indicates that the extension might be loaded for the CLI version of PHP, but your web server (likely Nginx or Apache) might be using a different PHP binary—perhaps one compiled without the extension, or one pointing to an older configuration directory where cURL was never installed.

The core technical reason for this discrepancy is that curl_init() is not a global function available across all PHP processes; it belongs to the specific process that loaded the extension. If your web server spawns a PHP-FPM pool or loads modules via Apache's .load directive, and those configurations do not include the cURL shared object, the web request will fail immediately upon encountering a cURL call. The CLI tool, however, often defaults to a system-wide configuration that explicitly enables cURL, leading to the false sense of security when checking from the terminal.

To resolve this, you must inspect the actual PHP binary used by your web server. You can determine which process is handling your request by adding a debug line at the very top of one of your failing routes or index files:

echo getmypid(); 
echo shell_exec('which php');

If the output of which php inside the script differs from the result of running which php in your terminal, you have identified a binary mismatch. The fix involves ensuring that the cURL extension is installed for the specific PHP version and binary used by your web server. On Debian-based systems like Ubuntu, this usually requires reinstalling the package specifically for the web server's PHP path:

sudo apt-get install php7.0-curl

Or, if you are using a newer version of PHP 7 (like 7.1 or 7.2), ensure you are installing the corresponding package (e.g., php7.1-curl). After installation, restart your web server to apply the new configuration:

sudo systemctl restart php7.0-fpm
sudo systemctl restart nginx # or apache2

Another common pitfall involves the zend_extension setting, though this is less relevant for cURL which is a regular extension. The real trap lies in assuming that because cURL works in one context (CLI), it works in another (Web). Developers often overlook the fact that shared libraries are loaded dynamically at runtime based on the specific binary's configuration. If your php.ini file in the web root or the global pool directory lacks the line extension=curl.so, the function will remain undefined regardless of what you see in your terminal grep output.

If you are using a framework like Laravel, ensure that your composer.json does not inadvertently lock you into a specific PHP version mismatch, and verify that your .env file doesn't force a different PHP binary via custom paths. For production environments managed by hosting providers or complex setups, it is advisable to check the php.ini files in both /etc/php/7.0/cli/conf.d/ and /etc/php/7.0/apache2/conf.d/ (or similar paths depending on your version) to ensure the cURL extension flag is active in both locations.

For those looking for deeper insights into managing PHP extensions across different environments, resources like https://laravelcompany.com can provide guidance on best practices for deploying PHP applications with specific dependency requirements. The key takeaway is that environment isolation means you must treat CLI and Web contexts as distinct entities requiring identical configurations to ensure functions like curl_init() are universally available.

Our network