Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REDIS php extension connect error

Tags:

php

redis

When I use redis PHP extension, I get the error, the host is 127.0.0.1 and the port is 6379.

Redis::connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known.

like image 725
hxc Avatar asked Oct 06 '22 22:10

hxc


2 Answers

I had the same issue happening sporadically on my local server with a number of attempted fixes yielding no resolution. This post here gave me an idea that seems to have finally fixed the problem.

Basically, I have a number of vhosts set up on my local machine (running Ubuntu) which allows me to use domain names to access locally-run sites instead of the usual 'localhost/sitename' approach. As a result, I had no IP assigned to 'localhost' name.

This might not be the same root cause for the problem for you, but here's how I've solved mine:

  1. See what is the value of 'redis-host' in your redis config file (for me it's set to 'localhost').
  2. In your /etc/hosts file check that there's an IP assigned to that host name. (In your case, where redis-host is 127.0.0.1, check that there isn't some other host name assigned to that IP, like phpmyadmin, for example.)

Of course, as a sanity check, make sure your redis-server is up and running, try rebooting Apache in case you've made any config changes, etc.

like image 79
Anna T Avatar answered Oct 09 '22 10:10

Anna T


For mac users:

Open terminal and try this command:

  1. sudo vi /etc/hosts
    (sudo to execute the command as a root user, You have enter the password for this)
  2. press 'i' to get into input mode of VI editor
  3. Add this line at the end 127.0.0.1 redis
  4. press esc to go to command mode
  5. type :wq (to save and quit the vi
    editor)
like image 43
Deepak G Avatar answered Oct 09 '22 12:10

Deepak G