elastic / elasticsearch-php

Official PHP client for Elasticsearch.
https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html
MIT License
5.26k stars 966 forks source link

The following error occurred:cURL error 77 #1298

Closed ilovelnmp closed 1 year ago

ilovelnmp commented 1 year ago

Summary of problem or feature request

cURL error 77: (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://elastic:34l_yt1s989Uk-UCUi'@192.17.1.71:9200/my_index/_doc

The [http.p12] file in the code is copied from the server to the local

    $client = ClientBuilder::create()
        ->setHosts(['https://192.17.1.71:9200'])
        ->setBasicAuthentication('elastic', '34l_yt1s989Uk-UCUi')
        ->setCABundle('/My local file path/ca/http.p12')
        ->build();

    $params = [
        'index' => 'my_index',
        'body'  => [ 'testField' => 'abc']
    ];

    try {
      $response = $client->index($params);
    } catch (ClientResponseException $e) {
      // manage the 4xx error
    } catch (ServerResponseException $e) {
      // manage the 5xx error
    } catch (Exception $e) {
      // eg. network error like NoNodeAvailableException
    }

    print_r($response->asArray());  // response body content as array

System details

ezimuel commented 1 year ago

@ilovelnmp I'm assuming you are using Elasticsearch 8 with elasticsearch-php 8. The cURL erro 77 is CURLE_SSL_CACERT_BADFILE and its related with SSL certificate. I see you are using the .p12 file format for the certificate. Can you try to convert it in .crt format as suggested in the documentation? If you have openssl installed you can use the following command:

openssl pkcs12 -in filename.p12 -clcerts -nokeys -out filename.crt

where the input is filename.p12 (in your case http.p12) and the output is filename.crt. Let me know if this fix the issue, thanks!