Recently I was working with some PHP code that made use of cURL, and found it wasn’t enabled on my Windows server. The error was similar to this:
Fatal error: Call to undefined function curl_init()
The good news is that PHP libcurl is bundled in the Windows PHP installation by default. It just has to be enabled.
What is PHP cURL?
The official PHP documentation describes the libcurl libarary as
"...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."
You’ll commonly see it used in PHP to make API calls to web servers, which was what my code was trying to do.
Enabling cURL in Windows
First you’ll need to know the location of the server’s
php.ini file, and have access to edit it.
If you don’t know the location of
php.ini you can follow step 1-3 below to locate it. If you already know where the
php.ini lives skip to step 4.
Create a new file
info.phpon your web server. Paste the following into the file and save:
<?php phpinfo(); ?>
Use a web browser to open
If PHP is configured correctly (hopefully it is!) you should see a heap of configuration information displayed.
Loaded Configuration Filesetting and note it’s value. This is the location of the
For example, it may be like:
Now we need to edit the
php.inifile and enable the libcurl extension.
php.inifile in a text editor
You should find a line similar to this:
It is commented out by the
;at the start of the line.
Uncomment the line (remove the preceeding
Note that you may need to set the absolute path to
php_curl.dlllocated within the
extdirectory of the PHP installation, for example:
Save the changes to
Restart the Apache httpd service
In your web browser reload the
info.phpand search for
You should find something like:
cURL support: enabled