I create a curl request with PHP to call API from another server
$ch=curl_init($url) ;
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1) ;
$re=curl_exec($ch) ;
echo curl_error($ch) ;
curl_close($ch);
but I got this error "SSL certificate problem: unable to get local issuer certificate" I searched and try a lot to solve this problem, but they did not work.
- one strange thing is happening and that is when I run the API URL in browser address tab it works but not work using curl in localhost , real host, postman.
what I did:
1- download cacert.pem and set the absolute path
curl_setopt($ch,CURLOPT_CAINFO,G:\Downloads\cacert.pem)
curl_setopt($ch,CURLOPT_CAPATH,'G:\Downloads\cacert.pem')
the path works because when I set wrong path returned error about wrong path.
2-change the path of curl.cainfo in php.ini
when I set
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
it works but I want secure way.
what I should do?
is some thing wrong with API server?
or my code and configuration?
why it work in browser but not in localhost , postman , real host?
I read something about ca bundle and I have no idea about what it is. please help me.