Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to undefined function curl_init() in WAMP server 3

Tags:

php

curl

wamp

I have been digging in StackOverflow for hours now but I still didn't manage to resolve this :(

I want to do a POST request with Curl to get an Auth token, but even though I:

  • Made sure extension=php_curl.dll is not commented out
  • Tried different versions of PHP
  • Downloaded the fixed curl extension and replaced it (reference)

My code:

  function getToken() {
    echo "start gettoken";

    $jsonStr = http_build_query(Array(
        "client_id" => "***",
        "scope" => "https://graph.microsoft.com/.default",
        "client_secret" => "***",
        "grant_type" => "client_credentials"
    ));
    $headers = Array("Content-Type: application/x-www-form-urlencoded");

    $ch = curl_init("https://login.microsoftonline.com/***.onmicrosoft.com/oauth2/v2.0/token");
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    $token = curl_exec($ch);
    echo "test after curl";
    var_dump($token);
    echo $token;
    return $token;

    curl_error($ch);


}

Can someone please help me with this issue?

like image 646
Y_Lakdime Avatar asked Feb 04 '26 09:02

Y_Lakdime


1 Answers

If you have installed a new Apache and a new version of PHP, you can migrate to the new Apache with the configurations of the old one via Apache→version.

For me CURL worked with PHP7.4 but not the other versions, then by migrating to the new Apache with the migration of data from the old Apache it worked.

like image 138
Alex Fritz Avatar answered Feb 05 '26 23:02

Alex Fritz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!