Facts
I have Apache/2.4.27 (Win64) PHP/7.2.0beta3 on Win 10 laptop. I want to implement cURL. This is my code
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://www.youtube.com');
curl_exec($curl);
if (curl_errno ( $curl )) {
echo curl_error ( $curl );
curl_close ( $curl );
}
that generates the error SSL certificate problem: unable to get local issuer certificate
. So I downloaded certificates from https://curl.haxx.se/ca/cacert.pem. Took the cacert.pem file, put it in the PHP folder and edited the php.ini
file like this
curl.cainfo = C:php/ext/cacert.pem
.
Problem
Now I get this error error setting certificate verify locations: CAfile: C:php/ext/cacert.pem CApath: none
. I googled and the only solution I found is that I have to download the .crt
file from the site I want to cURL and include it in my cURL like curl_setopt($curl, CURLOPT_CAINFO, "C:/wamp64/www/GIAG2.crt");
.
Problem 1.1 :
I dont know how to download the .crt
file so I can include it in my code, like the above example.
Problem 1.2 : That is not a "universal" solution, I want to set my certificates in such way that I dont have to download different certificates for different site.
Thank you
The easiest way is to skip this check.
The current CA Cert extracts provided by cURL contain the GeoTrust Global CA certificate authority which signed Google's CA cert which in turn signs YouTube's cert, so you should have no problem using the file you have.
Based on the last error, it looks like the problem is because you were missing the
/
afterC:
. The messageerror setting certificate verify locations
means that it couldn't open or read the file specified bycurl.cainfo
so it's not finding any certs at all.If you change
C:php/ext/cacert.pem
toC:/php/ext/cacert.pem
it should be able to read the CA file correctly and then verify the site properly.