# Php client can't connect to different port localhost

**URL:** <https://discuss.elastic.co/t/php-client-cant-connect-to-different-port-localhost/41115>\
**Category:** Elasticsearch\
**Created:** [February 6, 2016, 10:30am UTC](https://discuss.elastic.co/t/php-client-cant-connect-to-different-port-localhost/41115 "2016-02-06T10:30:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DrunkUnicorn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drunkunicorn/32/7635_2.png) [@DrunkUnicorn](https://discuss.elastic.co/u/DrunkUnicorn)\
**Post date:** [February 6, 2016, 10:30am UTC](https://discuss.elastic.co/t/php-client-cant-connect-to-different-port-localhost/41115/1 "2016-02-06T10:30:38Z")

</div>

I've installed last ElasticSearch version (2.2.0) to my vagrant, ant forwarded ports like 62000 host goes to 9200 guest, and everything works fine, localhost:62000 on my host machine returns me default information about ES, after setting CORS to enabled and node set as master, even my ElasticHQ now easily connects to it, but. But Elastic'a throws exception **Couldn't connect to host, Elasticsearch down?**

My test php code is:

```
$client = new Client([
    'host' => 'localhost',
    'port' => 62000
]);
$index = $client->getIndex('test');
$index->create(array(), true);
$type = $index->getType('test');
$type->addDocument(new Document(1, array('username' => 'ruflin')));
$index->refresh();

$query = array(
    'query' => array(
        'query_string' => array(
            'query' => 'ruflin',
        )
    )
);

$path = $index->getName() . '/' . $type->getName() . '/_search';

$response = $client->request($path, Request::GET, $query);
$responseArray = $response->getData();

```

I've also tried 127.0.0.1 instead of localhost, but no luck.

**Update**

Tried native elasticsearch php client as:

```
$hosts = [
    'http://127.0.0.1:62000',
];
$client = Elasticsearch\ClientBuilder::create()->setHosts($hosts)->build();
$client->search([]);

```

Getting **Uncaught Elasticsearch\Common\Exceptions\NoNodesAvailableException: No alive nodes found in your cluster**

**elasticsearch.yml edits:**

```
node.master: true
network.host: _non_loopback_
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"

```

What am i doing wrong?

---

<div class="post-metadata">

**Author:** ![DrunkUnicorn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/drunkunicorn/32/7635_2.png) [@DrunkUnicorn](https://discuss.elastic.co/u/DrunkUnicorn)\
**Post date:** [February 6, 2016, 12:09pm UTC](https://discuss.elastic.co/t/php-client-cant-connect-to-different-port-localhost/41115/2 "2016-02-06T12:09:46Z")

</div>

If i change

```
network.host: _non_loopback_

```

to

```
network.host: 127.0.0.1

```

i can connect to ES like this

```
$hosts = [
    'http://127.0.0.1:9200',
];
$client = Elasticsearch\ClientBuilder::create()->setHosts($hosts)->build();
$client->search([]);

```

but cannot reach it via 62000 port

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:18pm UTC](https://discuss.elastic.co/t/php-client-cant-connect-to-different-port-localhost/41115/3 "2017-07-05T23:18:26Z")

</div>


