Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rohansinghrawat's avatar

error "setting certificate verify locations:" while creating curl request

I am integrating an api given by our vendor and so far i have tried to do it with curl request as i was not able to do it with HttpClient , but in my curl request i have done all the things , let me show my code which i have done so far.

 try {
            $ch = curl_init();

            curl_setopt($ch, CURLOPT_URL, "my vendor url");
            // curl_setopt($ch, CURLOPT_CAINFO, public_path('keystore.p12'));
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
            curl_setopt($ch, CURLOPT_CAINFO, public_path('keystore.p12'));
            curl_setopt($ch, CURLOPT_CAPATH, public_path('keystore.p12'));
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, \Axis::encrypt(json_encode($request), $this->keyAsHexString));
            curl_setopt($ch, CURLOPT_HTTPHEADER, [
                "Content-Type" => "text/plain",
                "Accept" => "text/plain",
                "X-IBM-Client-Id" => "client-id",
                "X-IBM-Client-Secret" => "client-secret",
                "x-fapi-channel-id" => "INPAY",
                "x-fapi-epoch-millis" => "1660822921362",
                "x-fapi-uuid" => "UUIID",
                "x-fapi-serviceId" => "OpenAPI",
                "x-fapi-serviceVersion" => "1.0",
                "accesstoken" => "accessTokn",
            ]);

            $content = curl_exec($ch);

            // Check the return value of curl_exec(), too
            if ($content === false) {
                throw new \Exception(curl_error($ch), curl_errno($ch));
            }

            // Check HTTP return code, too; might be something else than 200
            $httpReturnCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

            /* Process $content here */

        } catch (Exception $e) {

            trigger_error(sprintf(
                'Curl failed with error #%d: %s',
                $e->getCode(), $e->getMessage()),
                E_USER_ERROR);

        } finally {
            // Close curl handle unless it failed to initialize
            if (is_resource($ch)) {
                curl_close($ch);
            }
        }

but i got this response

 error setting certificate verify locations:
  CAfile: /var/www/api-test4.instantpay.in/public/keystore.p12
  CApath: /var/www/api-test4.instantpay.in/public/keystore.p12

now the thing is i have to make my request encrypted and then send it to vendor and also there is one ca cert file which is required to make an secure connction so i have to attach that file too

also i made my file permissions to 777 so that it is accessible

-rwxrwxrwx  1 uatroot uatroot   7994 Aug 22 12:31 keystore.p12
-rwxrwx---  1 uatroot uatroot     24 Jan 19  2022 robots.txt
  1. now firstly i am not sure that is it right method to attach those ssl file
  2. also if yes then what does this error depicts
  3. and lastly is this process going in right way

please help me with this if anyone find it similiar

Thanks

0 likes
0 replies

Please or to participate in this conversation.