Upsun User Documentation

Set up Redis

Try Upsun for 15 days
After that, enjoy the same, game-changing Upsun features for less with the First Project Incentive!ยน A monthly $19 perk!
ยนTerms and conditions apply
Activate your 15-day trial

With Laravel, you can use Redis to handle session storage, cache storage, and queues.

1. Add the Redis service Anchor to this heading

  1. Add the service to your app configuration using the services top-level key:

    .upsun/config.yaml
    services:
        [...]
        redis:
           type: redis:7.0
  2. To connect the service to your app, add the following relationship:

    .upsun/config.yaml
    applications:
        myapp:
            [...]
            relationships:
               redis: "redis:redis"
    
    services:
        [...]
        redis:
            type: redis:7.0

2. Configure your Redis service Anchor to this heading

The Redis configuration is exposed via the following environment variables (where REDIS is the upper-cased version of the key defined in the relationship):

  • REDIS_URL: The Redis URL
  • REDIS_HOST: The Redis host
  • REDIS_PORT: The Redis port
  • REDIS_SCHEME: The Redis scheme

If the relationship is named redis, Laravel automatically detects these variables and configure its own Redis driver the right way. If not, you can map the variables in the .environment file.

You can specify the Redis client in your .environment file:

.environment
export REDIS_CLIENT="phpredis"

3. Store the Laravel cache in Redis Anchor to this heading

To enable cache storage in Redis, add the following environment variable to your .environment file:

.environment
export CACHE_STORE="redis"

4. Store Laravel sessions in Redis Anchor to this heading

Laravel relies on the SESSION_DRIVER variable to store sessions. Therefore, add the following environment variable to your .environment file:

.environment
export SESSION_DRIVER="redis"

5. Use Redis for Laravel queues Anchor to this heading

For a basic queueing system, configure the QUEUE_CONNECTION in your .environment file as follows:

.environment
export QUEUE_CONNECTION="redis"

For more information, see the Laravel Queues documentation and Upsun’s Horizon configuration page.

Is this page helpful?