Y_Lakdime
Y_Lakdime

Reputation: 825

Call to undefined function curl_init() in WAMP server 3

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:

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?

Upvotes: 3

Views: 1914

Answers (3)

Alex Fritz
Alex Fritz

Reputation: 1

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.

Upvotes: 0

Mehul Kuriya
Mehul Kuriya

Reputation: 608

For me this did the trick: http://www.phpmind.com/blog/2011/02/how-to-enable-curl-in-wamp/

1) Close WAMP (if running)

2) Navigate to WAMP\bin\php(your version of php)\

3) edit php.ini

4) Search for curl, uncomment extension=php_curl.dll

5) Navigate to WAMP\bin\Apache(your version of apache)\bin\

6) edit php.ini

7) Search for curl, uncomment extension=php_curl.dll

8 ) Save both

9) Restart WAMP

Upvotes: -1

Danyal Sandeelo
Danyal Sandeelo

Reputation: 12401

Enable php_curl.dll extension, seems like it's disabled. You can verify it by using

echo phpinfo();

or directly access the php.ini to check if it' disabled.

stop wamp server, open php.ini, search for this extension=php_curl.dll and uncomment it.

Save the file and restart the server.

Upvotes: 0

Related Questions