Often, web applications require HTTP based UserID and Password authentication, cookies, and form uploads. Even, user authentication with Google or Facebook sign-in is done via HTTP. In these types of cases, we need to request a particular service server(Like Google’s) for user validation and authentication token on our server. The entire process takes place through the service server’s APIs. The cURL helps our web applications to interact/communicate with those APIs on the HTTP level.
cURL: It is a library created by Daniel Stenberg. The cURL stands for client URL. It allows us to connect with other URLs and use their responses in our code. The cURL is a way that can hit a URL from our code to get an html response from it. The cURL is also used in command lines or scripts for data transfer. cURL with respect to PHP is a library that lets us make HTTP requests in PHP. It’s easier to do GET/POST requests with curl_exec to receive responses from other servers for JSON format data response and to download files.
Required to “enable” cURL: The cURL, by default, is not enabled in Apache. If we try to run CURL programs without enabling CURL in Apache, the browser will throw an error.
Fatal error: Call to undefined function curl_init()
To avoid this, we need to enable the CURL extension in the Apache server with the following methods in different environments.
Enable CURL in Apache: Enabling CURL in Apache by configuring php.ini file.
- Step 1: Locate PHP.ini file, it is mostly in the server’s root folder or public_html then open the PHP.ini in a text editor
- Step 2: Search or find the ;extension=php_curl.dll with Ctrl+F and remove the semi-colon ‘;’ before it to activate it.
- Step 3: Save and Close PHP.ini with Ctrl+S and restart Apache from terminal/CMD
Enabling cURL in WAMP: WAMP is a software stack available for Windows that bundle Apache, MySQL, and PHP together. It’s an installation pack for installing the three web technologies on the Windows environment together in a hassle-free GUI guided fashion.
- Step 1: Left-click on the WAMP server icon in the bottom right of the screen.
- Step 2: PHP -> PHP Extensions -> curl.
Enabling CURL in Ubuntu: Run the following command:
- This command installs the PHP CURL.
sudo apt-get install php5-curl
- This command starts with the Apache server.
sudo service apache2 restart
Check if CURL is enabled or not: If we try to run a cURL PHP program without cURL being enabled, the browser will throw the following error.
// Create curl resource
// set url
// Return the transfer as a string
, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
// Close curl resource to free up system resources
- Output: This page of GeekforGeeks is now rendered on my localhost running the Apache server. The HTML content is “echoed” as the output.
- PHP | cURL
- How to get cookies from curl into a variable in PHP ?
- How to Install php-curl in Ubuntu ?
- Difference between file_get_contents and cURL in PHP
- Why use Guzzle Instead of cURL in PHP ?
- How to install the ext-curl extension with PHP 7 ?
- curl command in Linux with Examples
- How to find where the URL will redirected using cURL?
- How to use cURL via a proxy ?
- How to enable PHP's openssl extension to install Composer ?
- jQuery | disable/enable an input element
- How to enable/disable all input controls inside a form element using jQuery ?
- How to enable Bootstrap tooltip on disabled button ?
- Web Browsers that support Java Applets and how to enable them
- How to make sure clients have enough words in textarea by using angularjs in order to disable/enable a button?
- How to enable routing and navigation between component pages in Angular 8 ?
- Express.js | app.enable() Function
- How to Enable Webcam in Angular 10 using ngx-webcam ?
- How to enable customers to know if your wordpress website delivers at their pincode or not?
- How to enable Button based on If statement in React.js ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.