2

I'm having issues with Windows MAMP Pro 3.3.1 getting PHP's CURL to work.

More specifically issue is that I can send requests to APIs using curl_exec, but it always returns false.

When I tried to do the same thing with XAMPP it returns full response with no issues.

I tried changing PHP version, I checked that php curl extensions is enabled and I can see CURL info in phpinfo.

Does any one know why and how to fix this issue with MAMP?

Jack
  • 108
  • 1
  • 2
  • 9

2 Answers2

9

So I've seen the issue. Apparently (still need to investigate), a CURL request does not get the certificate from the browser, unlike HTTPS. We'll need to manually download the certificate of the site and add it to the PHP ini.

I got the certificate from here:

https://curl.haxx.se/ca/cacert.pem

Add the path to php.ini. You should see ;curl.cainfo under [curl]. Uncomment and add the path:

curl.cainfo = "path_to_cert\cacert.pem"

Restart apache and it'll work (at least mine did).

ThomasV
  • 346
  • 3
  • 16
  • I dont' even have [curl] and [openssl] entries in any MAMP php.ini file. – Jack Feb 23 '18 at 15:16
  • 1
    Adding curl.cainfo = "path_to\cacert.pem" to php.ini did the trick. You should undo your answer so I can vote it up. – Jack Feb 23 '18 at 15:24
  • Thank you very much Thomas. I hope that MAMP will fix this issue in Windows MAMP 4. – Jack Feb 23 '18 at 15:27
  • 1
    In case it helps, my php.ini file is located at `/Applications/MAMP/bin/php/php7.1.1/conf/php.ini` – Gavin Mar 26 '19 at 06:57
  • I have this same issue, tried all the solution I've seen so far on this problem, still not solution. I'm using MAMP. In my php.ini i used `this curl.cainfo ="/Applications/MAMP/conf/apache/extra/cacert.pem"` as the url for curl. I used `var_dump(php_ini_loaded_file());` to get my php ini location, this was what I got `string(48) "/Applications/MAMP/bin/php/php7.2.8/conf/php.ini"` still no solution. Any other suggestion will be appreciated. – Pianistprogrammer Oct 16 '19 at 07:19
  • I checked this solution too, didn't help me either, please help https://stackoverflow.com/questions/28858351/php-ssl-certificate-error-unable-to-get-local-issuer-certificate – Pianistprogrammer Oct 16 '19 at 07:24
1

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);