Installing Redis Locally with Valet - Kevin McKee
Published on

Installing Redis Locally with Valet

Author

For a long time I have been doing local development with my Laravel Debugbar disabled because it was so slow it would literally crash my site. As soon as I disable it, everything is back to normal.

I started looking into the problem today and realized that by default, the Debugbar stores all its information in a file, but there is a redis driver. Knowing redis is much faster than a file driver, I wanted to give this a shot. Let's install redis locally.

Step one, install via homebrew:

brew install redis

Now that that is installed, let's start it up.

brew services start redis

Hopefully you see something like this:

To make sure it's working, run the redis-cli ping command: Hopefully you get a PONG back.

Now for it to work in my Laravel app, I need to make sure I have the predis package installed.

composer require predis/predis

I need to double check that my config is set properly. In your database.php file look for the redis section and find your client. In my case, the REDIS_CLIENT is set to default to 'predis' so I'm good. I could also add the environment variable if I wanted.

Lastly, to solve my original Laravel Debugbar problem, I need to go to the debugbar.php config file and set the storage driver to redis:

'storage' => [
    'enabled' => true,
    'driver' => 'redis', // redis, file, pdo, custom
    'path' => storage_path('debugbar'), // For file driver
    'connection' => null,   // Leave null for default connection (Redis/PDO)
    'provider' => '', // Instance of StorageInterface for custom driver
],

That's it. Turns out that still didn't solve my debugbar problem but at least I have redis installed locally now! I can change my session driver or queue driver to redis now so I can more closely mirror production in my local environment.

Want to talk about this post? Connect with me on Twitter →