Skip to content
Advertisement

PHP cURL error: SSL certificate problem: self signed certificate

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.

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement