Server information:
Ubuntu 14.04
Apache2

I installed PHP5 on my webserver and tried to run a script that contained a call to the function curl_init(). The server responded with an error indicating that the function curl_init() was undefined. I installed PHP-CURL and restarted my webserver and encountered the same error. I created an info.php file containing a call to the function phpinfo() and checked to see that the CURL extension was installed and not only did the page say that the module was installed but it also said that CURL was enabled. I'm still recieving an error saying that curl_init() is undefined. I've checked everywhere, even on some of the Ubuntu forums and have tried everything and nothing seems to fix it.

Does anyone have any idea what I might be able to do to get this fixed?

Thanks

Dani AI

Generated

What you saw, , is a classic mismatch between the PHP process serving requests and the one that actually loaded the cURL module. On Ubuntu 14.04 the package is php5-curl, and it must be enabled for the exact SAPI you run (Apache mod_php or php5-fpm). A graceful reload can leave old workers alive for a while, so it may look broken, then magically start working later when those workers exit.

Quick sanity check you can drop in the same vhost/docroot that fails:

<?php
echo 'SAPI: ' . PHP_SAPI . PHP_EOL;
var_dump(function_exists('curl_init'), extension_loaded('curl'));

If that prints false, false, cURL is not loaded for this SAPI. Fixes to try:

  • Install and enable for PHP 5:
    sudo apt-get install php5-curl && sudo php5enmod curl
  • Restart the right service(s):
    mod_php: sudo service apache2 restart
    php5-fpm: sudo service php5-fpm restart (and then Apache or nginx)
  • Verify which config is in use in that vhost: create an info.php there and check "Loaded Configuration File" and "Additional .ini files parsed" point to /etc/php5/apache2 (mod_php) or /etc/php5/fpm (FPM), and that 20-curl.ini is listed.
  • Make sure disable_functions in php.ini does not include any curl_* functions.
  • Avoid running two PHP handlers at once (e.g., an old CGI handler via .htaccess plus mod_php/FPM). Remove stray AddHandler/AddType lines and pick one stack.
  • If in doubt, do a hard bounce so no old workers linger:
    sudo apachectl stop && sleep 2 && sudo apachectl start

Side note: Ubuntu 14.04 is long past end of life; plan an upgrade so you keep getting security updates and supported PHP packages.

I solved the issue. Appearantly it just took some time for the server to start complying with everything that I installed. I checked back with my server this morning and everything worked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.