How to enable cURL in PHP?

The cURL extension of PHP helps our website to communicate with other websites and APIs with many different types of protocols, including HTTP, HTTPS, FTP, gopher, telnet, dict, file, and ldap protocols. cURL (client URL) is a library created by Daniel Stenberg.

We can also use cURL to perform HTTP form-based upload, proxies, cookies, and user+password authentication.

Error message when cURL is not enabled when WordPress’s AMP plugin is activated.

Or if you use the library’s function such as curl_init(), you will see this error message:

Fatal error: Call to undefined function curl_init()

Steps to enable cURL

In order to use cURL in any PHP applications, we need to enable it in php.ini file.

  • Open php.ini. The location of this file depends on the OS and software you use. For example, it should be C:\xampp\php\php.ini for XAMPP or /etc/php/7.2/apache2/php.ini for Debian Apache. You can pinpoint the exact location by using phpinfo() function in a PHP file.
  • Browse to ;extension=curl line.
  • Remove the ; character before extension to register cURL extension.
  • Restart Apache or nginx server.

If cURL is enabled successfully, you will see this part when printing out phpinfo().

An example of how to use cURL:

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, ""); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$output = curl_exec($ch); 

echo $output; 


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.