zraikat
By:
zraikat

Elasticsearch request failed: 7 - Failed to connect to 45.55.134.XXX port 9200: Connection refused

March 22, 2015 5.6k views
PHP Frameworks NoSQL Ubuntu

I'm trying to use Elasticsearch in Yii 2.0. I'm able to connect to it using cURL from command line, but from my php code I get the above error.

3 comments
  • I would write a small php script outside of your Yii app to try to isolate the problem. If that doesn't help then check out your system logs, you may have something like AppArmor blocking the connection.

    Finally, you could try capturing the connection using 'tcpdump port 9200' and see what's going on at the network level.

  • Thanks. I ran the below php script outside of Yii and it worked. I guess this means its a Yii thing. tcpdump doesn't show any activity even when the script is working.

    $curlString = 'curl -X GET \';
    $curlString .= 'http://localhost:9200/tutorial/helloworld/1';
    $response = exec($curlString);
    echo($response);

  • I am having a similar issue.

    I can connect with curl via the command line and via a php script, I only seem to get a connection error when connecting via Yii2. Older apps that are using a different Elasticsearch lib still seem to work.

    Did you find the problem? I have a feeling it has something to do with the version of Elasticsearch not being compatible with Yii2's Elasticsearch library.

Be the first one to answer this question.