I am using Predis PHP library to connect to redis server running on AWS EC2 server. When I try to connect to redis installed on my local system, it works fine. Same code does not work when I try to connect to Redis on AWS EC2. I receive below error.
php_network_getaddresses: getaddrinfo failed: No such host is known. [tcp://my-server-address:6379]
I tried to check connect server on redis-cli using below command and it works fine.
redis-cli -h my-server-address -p 6379
below is the code PHP that I use to connect to Redis.
function config() {
$client = new Predis\Client([
'scheme' => 'tcp',
'host' => 'my-server-address',
'port' => 6379,
'database' => 1,
]);
return $client;
}
I made sure that there is nothing wrong with my server address.
Related
On a Nextcloud install I am receiving the error
No memory cache has been configured. To enhance performance, please configure a memcache, if available. Further information can be found in the documentation.
So I have installed APCu, Redis, redis-php and made the required settings in NCs config.php
'memcache.local' => '\OC\Memcache\APCu',
'memcache.locking' => '\OC\Memcache\Redis',
'memcache.distributed' => '\OC\Memcache\Redis',
'filelocking.enabled' => 'true',
'redis' =>
array (
'host' => '127.0.0.1',
'port' => '6379',
When I test the redis connection
redis-cli ping
I get a
PONG
(This works both w/ localhost and unix socket)
But Nextcloud obviously does not connect to Redis.
The http user is a member of the redis group.
php-redis module is activated.
Solved. The issue was with the location of the above code inside Nextcloud's config.php.
Now it is working as expected.
UPDATED INFO
With dd($clientBuilder->transport->getLastConnection()->getLastRequestInfo());
I could log out the following
"curl" => array:2 [
"error" => "Failed to connect to localhost port 30003: Connection refused"
But the thing is Elasticsearch is available under localhost:30003 via the web browser
The sample output when reaching this site:
{
"name": "xyz",
"cluster_name": "docker-cluster",
...
}
I did configure the host
$clientBuilder = ClientBuilder::create()
->setHosts(['http://localhost:30003/'])
->build();
When I dd($clientBuilder), the host is set to localhost:30003
#serializer: SmartSerializer {#385 …}
#transportSchema: "http"
#host: "localhost:30003"
#path: "/"
Again, the server is up and running, I can reach it via the web browser but I still get the error message:
No alive nodes found in your cluster
Elasticsearch version: 6.7.0
Elasticsearch PHP Version: 6.7.0 (latest)
In my docker-compose file, I'm mapping the port 30003 to 9200
ports:
- "30003:9200"
Elasticsearch did not cause the error.
cURL had an error 7 which means that it could not establish a connection.
My solution I came up with was the following:
$clientBuilder = ClientBuilder::create()
->setHosts([
[
'host' => 'docker.for.mac.localhost',
'port' => '30003'
]
])
->build();
I switched from localhost to docker.for.mac.localhost
This helped because I'm using docker container and each container has a different ip adress
I am using mongoDB with PHP. on local system it works fine. Now I am trying to access mongoDB cluster on AWS which is secured by SSH. I am using below code
$conn = new MongoClient('mongodb://SSH Hostname', [
'username' => 'username',
'password' => '',
'db' => 'DBname'
]);
print_r($conn);
It gives below error
Type: MongoConnectionException
Message: Failed to connect to: SSH Hostname :27017: Connection refused
I can connect DB from MongoDB compass or Studio 3T. How I can use SSH while connecting using PHP
This is how I am attempting to connect to the database on heroku:
//db.php
$config = array(
'username' => 'username',
'password' => 'password',
'connection_string'=> sprintf('mongodb://%s:%d','EXAMPLE.herokuapp.com','27017')
);
$connection = new \MongoClient($config['connection_string']);
When I pushed to the repo, and go to the app URL the follow error message is shown:
Failed to connect to: EXAMPLE.herokuapp.com:27017 Connection refused in db.php.
How should I format the connection_string so that it will not give the error message?
There is no locally running MongoDB available on Heroku.
You need to use one of the add-ons at https://addons.heroku.com/#data-stores such as MongoLab.
When you run
$ heroku addons:add mongolab
it's provisioned for you, and there will be a config variable in the environment with the connection information:
$ heroku config | grep MONGOLAB_URI
MONGOLAB_URI => mongodb://heroku_app1234:random_password#ds029017.mongolab.com:29017/heroku_app1234
You can just read that from $_ENV['MONGOLAB_URI'], or using getenv('MONGOLAB_URI'):
$connection = new \MongoClient(getenv('MONGOLAB_URI'));
I'm trying to connect to pgsql via laravel and finally got everything setup (pgsql server running, pdo installed, all libs installed). I'm running on a VPS (CentOS) managed via CPanel/WHM.
Here's what I'm doing:
I'm trying to create a user database via artisan (Laravel's command line) using migrate:install.
For those that don't use Laravel, artisan uses php's PDO for pgsql to connect. Here are my settings:
'pgsql' => array(
'driver' => 'pgsql',
'host' => 'localhost',
'database' => 'dbname',
'username' => 'username',
'password' => 'password',
'charset' => 'utf8',
'prefix' => '',
),
I've also setup a test.php file:
$dbconn = pg_connect("host=localhost port=5432 dbname=dbname user=username password=password");
which also fails. I used phpPgAdmin to see what's up and all of the permissions are set correctly, the database shows up, the username is correct, same with password. I checked where postgre (version 8.4.12 btw) was running and phpPgAdmin tells me "localhost:5432".
The error I get via the command line is the following:
SQLSTATE[08006] [7] FATAL: no pg_hba.conf entry for host "::1", user "myusername", database "my_database", SSL OFF
Now, I tried to find the pg_hba.conf file but I'm not entirely sure where to look for it. Same goes for the error/access logs for pg and google hasn't been any help as far as this goes.
Any idea on what I can do?
localhost points to IPV6 ::1 address on your system. Postgresql makes the difference between ipv6 and ipv4 addresses when dealing with access list.
I was able to install/configure everything correctly. I changed the "host" to 127.0.0.1, not sure why that made a difference but it did :)