curl init function not working

curl init function not working  using -'php,lampp'

Hi I tries PHP Post Request inside a POST Request thinking it might be useful to me and my code is given below

$sub_req_url = "http://localhost/index1.php";

$ch = curl_init($sub_req_url);
$encoded = '';

// include GET as well as POST variables; your needs may vary.
foreach($_GET as $name => $value) {
  $encoded .= urlencode($name).'='.urlencode($value).'&';

foreach($_POST as $name => $value) {
  $encoded .= urlencode($name).'='.urlencode($value).'&';

// chop off last ampersand
$encoded = substr($encoded, 0, strlen($encoded)-1);

curl_setopt($ch, CURLOPT_POSTFIELDS,  $encoded);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);

form the index.php file and index2.php is another file in the same directory and when i open the page i get the following error in my error.log file

[Sat Dec 18 15:24:53 2010] [error] [client ::1] PHP Fatal error:  Call to undefined function curl_init() in /var/www/testing1/index.php on line 5

What i want to do is I have a reservation form that send post request and then i want to process post values and send again post request to paypal

asked Sep 30, 2015 by yogeshplv
0 votes

7 Answers

0 votes

You need to install CURL support for php.

In Ubuntu you can install it via

sudo apt-get install php5-curl

If you're using apt-get then you won't need to edit any PHP configuration, but you will need to restart your Apache.

sudo /etc/init.d/apache2 restart

If you're still getting issues, then try and use phpinfo() to make sure that CURL is listed as installed. (If it isn't, then you may need to open another question, asking why your packages aren't installing.)

There is an installation manual in the PHP CURL documentation.

answered Sep 30, 2015 by jekbishnoi
0 votes

For Windows, if anybody is interested, uncomment the following line (by removing the ;) from php.ini


Restart apache server.

answered Sep 30, 2015 by vickeykumar66
0 votes

In my case, in Xubuntu, I had to install libcurl3 libcurl3-dev libraries. With this command everything worked:

sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
answered Sep 30, 2015 by virendra.bajaj
0 votes

For Ubuntu: add to php.ini to enable, if necessary. Then sudo service apache2 restart

this is generally taken care of automatically, but there are situations - eg, in shared development environments - where it can become necessary to re-enable manually. The thumbprint:

  • Fatal Error on curl_init() call
  • in php_info, you will see the curl module author (indicating curl is installed and available)
  • also in php_info, you will see no curl config block (indicating curl wasn't loaded)

fatal error on curl_init() call

answered Sep 30, 2015 by gauravg.gwl
0 votes

(Trying to get Curl working via PHP and Apache on Windows...)

I kept getting an error saying: Call to undefined function 'curl_init()'

I made sure I had enabled curl with this line in my php.ini file: extension=php_curl.dll

I made sure the extension_dir variable was being set properly, like this: extension_dir = "ext"

I was doing everything everyone else said on the forums and curl was not showing up in my call to phpinfo(), and I kept getting that same error from above.

Finally I found out that Apache by default looks for php.ini in the C:\Windows folder. I had been changing php.ini in my PHP installation folder. Once I copied my php.ini into C:\Windows, everything worked.

Took me forever to figure that out, so thought I'd post in case it helps someone else.

answered Sep 30, 2015 by ajit.chavhan
0 votes

RusAlex answer is right in that for Apache you have to install and enable curl and restart your apache service:

sudo apt-get install php5-curl
sudo service apache2 restart

On my Ubuntu Server with nginx and php5-fpm I however ran into the following problem. I had to restart nginx and php5-fpm like so:

sudo service nginx restart
sudo service php5-fpm restart

But I had non-working php5-fpm processes hanging around, which apparently is a bug in ubuntu So I had to kill all idle php5-fpm processes to able to restart php5-fpm so that the curl module is actually loaded

sudo kill 
answered Sep 30, 2015 by kotmus2002
0 votes

To fix this bug, I did:

  1. In php.ini file, uncomment this line: extension=php_curl.dll
  2. In php.ini file, uncomment this line: extension_dir = "ext"
  3. I restarted NETBEANS, as I was using Built-in server
answered Sep 30, 2015 by rajeevr642