---
title: Laravel and Redis
layout: framework_docs
objective: Notes and configurations on connecting with the "in-memory data store", [Redis](https://redis.io/)
order: 3
---
[Redis](https://redis.io/) is a NoSQL database popularly used for cache storage, as a message broker, and even as a primary database. You can run your own Redis Fly App, or get one running and managed through Upstash Redis.
## _Laravel and Redis Fly App_
You can set up your own Redis Fly App either through Fly.io's Redis Docker Image, or through Redis' Official Docker Image.
### _Fly.io Redis Docker Image_
1. First create a new directory and initialize it with `fly launch`, using [Fly.io's Redis Image](https://hub.docker.com/r/flyio/redis/tags) for the build:
```cmd
mkdir fly-redis
cd fly-redis
fly launch --image flyio/redis:6.2.6 --name fly-redis --region ams --no-deploy
```
- Pull the <b>flyio/redis:6.2.6</b> image from the Docker repository through `--image` argument.
- You can specify your Redis Fly App name through the `--name` argument
- You can specify your region code through the `--region` attribute
- You can opt not to immediately deploy by adding `--no-deploy` argument
<br><br>
2. Afterwards, add a [volume](/docs/volumes/) that will persist your Redis data
```cmd
fly volumes create redis_server --size 1
```
- You can specify any volume name to replace redis_server above
- You can specify your preferred volume size in GB through the `--size` argument
<br><br>
3. Then, attach your volume to your Redis Fly App by revising its `fly.toml` to include `[[mounts]]`:
```toml
app = "fly-redis"
# Your primary region may differ
primary_region = "ams"
[build]
image = "flyio/redis:6.2.6"
[[mounts]]
destination = "/data"
source = "redis_server"
```
- Under `[[mounts]]` attach the volume created in step #2, make sure that the name specified for the created volume is exactly the same string specified for its `source` attribute</li>
<br><br>
4. Next, set up the Redis Fly App <b>password</b> through `fly secrets`
```cmd
fly secrets set REDIS_PASSWORD=<redacted>
```
5. Finally, deploy your Redis Fly App!
```cmd
fly deploy
```
### _Redis Official Docker Image_
If you would like to use [Redis' official docker image](https://hub.docker.com/_/redis) to set up your Redis Fly App, the steps to get up and running are almost identical to the previous guide. There is just one minor revision on the image pulled and an additional step to set the Redis Fly App's password.
1. Follow the steps [above](/docs/laravel/the-basics/databases#setup-using-the-fly-io-redis-docker-image), with a revision to the value passed for `--image`
```cmd
mkdir off-redis
cd off-redis
fly launch --image redis --name off-redis --region ams --no-deploy
```
- Pull the <b>redis</b> image from the Docker repository through the `--image` argument.
2. Before deploying, make sure to revise your `fly.toml` file to specify your Redis Fly App's password.
Add the `[processes]` section for the default `app` process and add the following commands:
```toml
[processes]
app = "sh -c exec redis-server --requirepass \"$REDIS_PASSWORD\""
```
- Use the `fly secret` <b>`REDIS_PASSWORD`</b> you've configured earlier
- If this passphrase is not set and your Laravel configuration sends a REDIS_PASSWORD during its connection to your Redis Fly App, watch out! You'll get the infamous "ERR Client sent AUTH, but no password is set" error
### _Connect from a Laravel Fly App_
Now that you have your Redis Fly App running, the next step is to connect it with your Laravel Fly App! Follow the steps below:
1. First, retrieve your Redis Fly App's [Fly .internal Address](/docs/networking/private-networking/#fly-io-internal-addresses).
2. Next, make sure you move to your Laravel Fly App's directory for better navigation:
```cmd
cd <laravel-app-folder>
```
3. Then revise your Laravel Fly App's `fly.toml` `[env]` configuration with the retrieved Fly .internal Address:
```toml
[env]
...
REDIS_HOST= "<redis_app_name>.internal"
CACHE_DRIVER= "redis"
```
4. Make sure you set your Laravel Fly App's `REDIS_PASSWORD` through the `fly secrets` command:
```cmd
fly secrets set REDIS_PASSWORD=<redacted>
```
5. Finally, deploy!
```cmd
fly deploy
```
That's it! Your Laravel and Redis Fly Apps should now be connected.
### _Connect from a local environment_
The simplest way to connect your local Laravel application to a Redis Fly App is to use `fly proxy`:
1. Open your Redis Fly App's local directory
```cmd
cd off-redis
```
2. Then run the `fly proxy` for port 6379 or whichever REDIS_PORT you have configured:
```cmd
fly proxy 6379
```
3. Next, revise your local Laravel application's .env file to update your Redis connection:
```env
CACHE_DRIVER=redis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=<redacted>
REDIS_PORT=6379
```
Make sure the REDIS_PORT in your .env configuration matches the port used in `fly proxy`
That's it! Your local Laravel application should now be connected with your Redis Fly App.
## _Laravel with Upstash Managed Redis Fly App_
Want a fully-managed Redis Fly App? Try [Upstash Redis](https://upstash.com/)! To set up, you can follow our-in-depth guide [here](/docs/upstash/redis/)
Once you've configured the necessary details through the flyctl prompts, and the app deployment completes, you should get a summary of the Redis cluster you've just deployed, like so:
```output
Your Upstash Redis database blue-brook-3843 is ready.
Apps in the personal org can connect to at redis://default:<redacted>@fly-blue-brook-3843.upstash.io
If you have redis-cli installed, use fly redis connect to connect to your database.
```
### _Connect From a Laravel Fly App_
To test whether your Laravel Fly App can successfully connect with your Upstash Redis database, you can use your Upstash Redis Fly App as your Cache driver, then perform a quick cache:clear command.
1. Revise the `[env]` configuration in your Laravel Fly App's `fly.toml` file:
```toml
[env]
...
CACHE_DRIVER="redis"
REDIS_URL="redis://default:<redacted>@fly-blue-brook-3843.upstash.io"
REDIS_CACHE_DB=0
```
- Set the Laravel cache driver to redis
- Using `REDIS_URL` should override `REDIS_HOST`, add here the `REDIS_URL` received during `fly redis create`
- Upstash only supports "database 0", so update your `REDIS_CACHE_DB` config to 0. Otherwise, you will receive an error : `SELECT failed: ERR Only 0th database is supported! Selected DB: 1...`
<br><br>
2. Then deploy your `fly.toml` changes:
```cmd
fly deploy
```
## Testing Connection
In all examples above, Redis was used as our Laravel application's Cache Driver.
To test if this connection is working or not, a simple `php artisan cache:clear` should let you know.
Laravel and Redis
Redis is a NoSQL database popularly used for cache storage, as a message broker, and even as a primary database. You can run your own Redis Fly App, or get one running and managed through Upstash Redis.
Laravel and Redis Fly App
You can set up your own Redis Fly App either through Fly.io’s Redis Docker Image, or through Redis’ Official Docker Image.
Fly.io Redis Docker Image
First create a new directory and initialize it with fly launch, using Fly.io’s Redis Image for the build:
Pull the flyio/redis:6.2.6 image from the Docker repository through --image argument.
You can specify your Redis Fly App name through the --name argument
You can specify your region code through the --region attribute
You can opt not to immediately deploy by adding --no-deploy argument
Afterwards, add a volume that will persist your Redis data
fly volumes create redis_server --size 1
You can specify any volume name to replace redis_server above
You can specify your preferred volume size in GB through the --size argument
Then, attach your volume to your Redis Fly App by revising its fly.toml to include [[mounts]]:
app="fly-redis"# Your primary region may differprimary_region="ams"[build]image="flyio/redis:6.2.6"[[mounts]]destination="/data"source="redis_server"
Under [[mounts]] attach the volume created in step #2, make sure that the name specified for the created volume is exactly the same string specified for its source attribute
Next, set up the Redis Fly App password through fly secrets
fly secrets set REDIS_PASSWORD=<redacted>
Finally, deploy your Redis Fly App!
fly deploy
Redis Official Docker Image
If you would like to use Redis’ official docker image to set up your Redis Fly App, the steps to get up and running are almost identical to the previous guide. There is just one minor revision on the image pulled and an additional step to set the Redis Fly App’s password.
Follow the steps above, with a revision to the value passed for --image
Use the fly secretREDIS_PASSWORD you’ve configured earlier
If this passphrase is not set and your Laravel configuration sends a REDIS_PASSWORD during its connection to your Redis Fly App, watch out! You’ll get the infamous “ERR Client sent AUTH, but no password is set” error
Connect from a Laravel Fly App
Now that you have your Redis Fly App running, the next step is to connect it with your Laravel Fly App! Follow the steps below:
Make sure the REDIS_PORT in your .env configuration matches the port used in fly proxy
That’s it! Your local Laravel application should now be connected with your Redis Fly App.
Laravel with Upstash Managed Redis Fly App
Want a fully-managed Redis Fly App? Try Upstash Redis! To set up, you can follow our-in-depth guide here
Once you’ve configured the necessary details through the flyctl prompts, and the app deployment completes, you should get a summary of the Redis cluster you’ve just deployed, like so:
Your Upstash Redis database blue-brook-3843 is ready.
Apps in the personal org can connect to at redis://default:<redacted>@fly-blue-brook-3843.upstash.io
If you have redis-cli installed, use fly redis connect to connect to your database.
Connect From a Laravel Fly App
To test whether your Laravel Fly App can successfully connect with your Upstash Redis database, you can use your Upstash Redis Fly App as your Cache driver, then perform a quick cache:clear command.
Revise the [env] configuration in your Laravel Fly App’s fly.toml file:
Using REDIS_URL should override REDIS_HOST, add here the REDIS_URL received during fly redis create
Upstash only supports “database 0”, so update your REDIS_CACHE_DB config to 0. Otherwise, you will receive an error : SELECT failed: ERR Only 0th database is supported! Selected DB: 1...
Then deploy your fly.toml changes:
fly deploy
Testing Connection
In all examples above, Redis was used as our Laravel application’s Cache Driver.
To test if this connection is working or not, a simple php artisan cache:clear should let you know.