GiuGent
GiuGent

Reputation: 1

PHP CURLSSLOPT_NATIVE_CA returns 'SSL certificate problem: unable to get local issuer certificate'

I'm trying to access an url which has SSL certification and use https using php curl inside a Windows Server 2016 enviroment. The curl options in the php code are set as follows:

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://awebsite.com",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_SSL_OPTIONS => CURLSSLOPT_NATIVE_CA, 
]);

$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);

The above curl code returns the following error: SSL certificate problem: unable to get local issuer certificate The version of PHP is 8.3.12 and the version of the curl extension is 8.7.0. The extension php_openssl.dll is enabled in php.ini. 'CURLSSLOPT_NATIVE_CA' is defined: I have checked this with the php function 'defined'

If I adopt the alternative solution to set in the php.ini file the curl.cainfo to the cacert.pem file downloaded from the Curl project (the CURLOPT_SSL_OPTIONS is not set in this case), I'm able to access the url.

I would use the CURLSSLOPT_NATIVE_CA option, but it seems that this setting is either ignored or php/curl cannot access system’s root certificates defined in Windows Serves. Maybe, some settings in the Windows and/or PHP environment are missing ? Otherwise, what else to fix this trouble ?

Upvotes: 0

Views: 111

Answers (0)

Related Questions