Laravel Homestead Redis Port Forwarding

14,687

Solution 1

For Homestead 0.4 above. Due to redis security setting, it bind only for 127.0.0.1

In this case, you need to bind extra IP address.

  1. SSH to you server.

$sudo vi /etc/redis/redis.conf

Scroll to the line bind 127.0.0.1 add extra IP address 192.168.10.10, it will look like this

bind 127.0.0.1 192.168.10.10

save and exit.

  1. Restart redis server and exit your server.

$sudo /etc/init.d/redis-server restart

That's all, you should be able connect to your Homestead redis from your host.

Solution 2

SSH to the machine and open /etc/redis/redis.conf.

Find line which starts with bind directive, comment it out and save the file. Then restart redis-server with sudo /etc/init.d/redis-server restart.

Thanks to that Redis will listen for all connections from all available interfaces. You don't need any extra port forwarding.

Solution 3

Remove ports settings from your Homestead.yaml you won't need it.

Now by default redis in homestead vm is listening on its normal port, 6379.

You can ssh into your vm and check it:

vagrant@homestead:~$ ps -aux | grep redis
redis      996  0.1  0.4  35232  8752 ?        Ssl  01:53   0:00 /usr/bin/redis-server *:6379

To connect to the vm's redis instance from your local machine you need to use an IP address that is specified in your Homestead.yaml. By default it is 192.168.10.10:

redis-cli -h 192.168.10.10

If you have domain name set up in your local /etc/hosts for your app you can use it instead:

redis-cli -h homestead.app

Solution 4

  1. SSH to your server.

    $sudo vi /etc/redis/redis.conf

Scroll to the line bind 127.0.0.1 and change to 0.0.0.0, it will look like this

bind 0.0.0.0

save and exit.

  1. Restart redis server and exit your server.

    $sudo service redis-server restart

That's all, you should be able connect to your Homestead redis from your host.

redis-cli -h 192.168.10.10
Share:
14,687
Rafael Beckel
Author by

Rafael Beckel

I started writing code when I was 6 years old and since then I knew I wanted to work with computers for the rest of my life. I am a curious person and an extremely fast learner, so one of my strongest assets is the ability to adapt to any working environment and new technologies on-the-fly. I like to be surrounded by extremely smart people, into challenging and inspiring environments, where we can help each other to learn and grow.

Updated on June 17, 2022

Comments

  • Rafael Beckel
    Rafael Beckel almost 2 years

    I'm having some trouble here trying to remotely connect to my local Homestead Redis server. I'm using both commandline (redis-cli) and RDM.

    I'm able to connect with Postgresql with PgAdmin in this box, but Redis returns with:

    Could not connect to Redis at 127.0.0.1:63790: Connection refused

    My Redis config file "bind" directive is commented, so it should accept connections from all sources. I also tried to stop Redis and start it again, manually pointing to the config file, but without success.

    In my Homestead.yaml config file, Redis port was not forwarded by default. According to Homestead's Documentation, I can set port forwarding like this:

    ports:
        - send: 63790
          to: 6379
          protocol: udp
    

    Well, I also tried that and restarted the server, but it didn't work.

    Am I missing something?

  • Rafael Beckel
    Rafael Beckel almost 9 years
    Works like a charm! I just opened a pull request in Laravel's docs to add your instructions to connect to Redis.
  • gabe.
    gabe. about 8 years
    I don't think this is the case anymore with the latest homestead VM -- it seems that redis only listens on 127.0.0.1 now. So, back to port forwarding it is.
  • Gerardo Jaramillo
    Gerardo Jaramillo about 7 years
    Awesome Stuff!!
  • mike.bronner
    mike.bronner over 6 years
    I found that instead of using 192.168.10.10, you now need to use the IP address specified in your /etc/hosts file, instead of the IP address specified in your Homestead.yaml file. For me that IP address was 10.211.55.5.
  • sunscreem
    sunscreem over 6 years
    This worked for me (windows 10, homestead v5) but I also had to set protected-mode no too.
  • Pathros
    Pathros over 4 years
    With the new Laravel Homestead 9.0.1 This problem arose. Following these steps in Laravel Homestead did the trick ... but I don't know why the email verification started to send lots of emails to my email trap account :/
  • Darren Murphy
    Darren Murphy about 3 years
    You're a live-saver! I was looking for the /etc/redis/redis.conf file on my computer, instead of in the vagrant installation. Suddenly dawned on me, after reading your answer, that I was making that mistake. Now my cache works and clears ;)