John Davidson

php - How to correctly setup REDIS with DDEV / DOCKER for Laravel local?

0 comments
Message:


I am looking to setup Redis in my local dev environment, I am using DDEV in Laravel Projects.


I've followed the steps here to add redis to the project:
https://github.com/drud/ddev-contrib/tree/master/docker-compose-services/redis


After a ddev restart I can see Redis is getting pulled into the container however it instantly falls over which you can see from running a docker ps -a.



Please would somebody be able to help with the correctly setting this up for a laravel project?


Just for reference I am on a MacbookAir 2021 BigSur M1 Chipset.



My Answer:
To correctly set up Redis with DDEV and Docker for a Laravel project, you can follow these steps:

1. Add the Redis service to your DDEV configuration by creating a `docker-compose.redis.yaml` file in the `.ddev` directory of your Laravel project. You can use the following configuration:

yaml
version: '3.6'

services:
redis:
image: redis:alpine
container_name: ${DDEV_SITENAME}-redis
ports:
- "6379:6379"


2. Update your `docker-compose.override.yaml` file in the `.ddev` directory to include the Redis service:

yaml
version: '3.6'

services:
web:
ports:
- "8080:80"
db:
ports:
- "3306:3306"
redis:
external: true


3. Restart DDEV by running `ddev restart`.

4. Update your Laravel project's `.env` file to use Redis as the cache and session driver. Update the following lines:


CACHE_DRIVER=redis
SESSION_DRIVER=redis
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379


5. Finally, clear your Laravel project's cache by running `php artisan cache:clear`.

After following these steps, Redis should be correctly set up with DDEV and Docker for your Laravel project. You can now use Redis for caching and session management in your local development environment.

Rate this post

5 of 5 based on 4635 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us