Fatal error: Call to undefined function: curl_init() CodeUnit 24 JUN 2009

PHPPretty damn useful: Client URL Library, or cURL for short. From the pages of PHP.net:

PHP supports libcurl, a library created by Daniel Stenberg, that allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHP’s ftp extension), HTTP form based upload, proxies, cookies, and user+password authentication.

If however you keep getting the error message Fatal error: Call to undefined function: curl_init() when you try running a PHP script or two on your server, then I’m afraid you currently don’t have this great little library enabled and as such, really should think about installing it ASAP.

So how do you do it?

Well first, let’s make sure that our diagnosis is in fact correct. Whip up a quick check page by creating a .php file with a phpinfo(); command in it and upload it to your server. Browse to file’s URL and search for ‘curl’ on the resulting page. If cURL support is enabled, then there will definitely be a listing for it.

If however it doesn’t appear on the page, you’ll need to go about enabling it yourself. Of course, if you are with a hosting company and not in control of the server yourself, simply ask them to do it for you! :)

Otherwise, if you are running a linux-based system, you need to ensure that your PHP is compiled with cURL support and the libcurl library needs to be installed. To install the php5-curl package, run sudo apt-get install php-curl and then restart the Apache web server with sudo /etc/init.d/apache2 restart.

If you are running a Windows-based system, cURL can be enabled by simply editing the php.ini file to remove the semi-colon in front of the extension=php_curl.dll line and then restarting the web server service/application.

(Note: If you get an error Unable to Load X:/path/php/ext/php_curl.dll error, locate and copy the ssleay32.php and libeay32.dll (OpenSSL) libraries to your system32 folder.)

Related Posts:

About Craig Lotter

South African software architect and developer at Touchwork. Husband to a cupcake baker and father to two little girls. I don't have time for myself any more.