1

Long story short, I had to reinstall php 7.4 on my Mac. I have a php webapp that hits a .NET API. Prior to the reinstall of php, I was able to hit a locally running version of my API at https://localhost:5001 using cURL in php but now I get a response code of 0 with this error:

Curl error: SSL certificate problem: self signed certificate

If I point the same php code to my production API, everything works fine. I am able to successfully hit the local version of the API with Postman.

I tried the accepted answer from this post but it did not work for me even after restarting apache and my computer. I tried both the php.ini and runtime approaches but neither solved my problem.

1 Answers1

2

You should append the public key of your self signed certificate to the cacert.pem file. Then either of the solutions (setting curl.cainfo in php.ini OR explicitly specifying the path to the cacert.pem file using CURLOPT_CAINFO) proposed here should work just fine.

Make sure you respect the format of the cacert.pem file when adding your public key.

Zoli Szabó
  • 4,366
  • 1
  • 13
  • 19
  • This worked for me, thank you so much for your help. For anyone who might be reading this later, use this command to get your localhost public key: ``` openssl s_client -connect localhost:5001 ``` – Adam LeVasseur Jan 01 '22 at 19:18
  • @AdamLeVasseur Can you please explain a little more how you made that work, I am stuck on the same problem. – pyrogrammer Jan 04 '23 at 15:38
  • @pyrogrammer With my API running locally on port 5001 I ran the command specified above in a terminal window. Then I pasted the certificate from that output to the bottom of cacert.pem. – Adam LeVasseur Jan 11 '23 at 03:47