Enable Redis cache on Laravel Forge

Laravel Forge comes with Redis and phpredis installed, but there are a couple extra steps to use Redis cache with your Laravel application.

First, tell PHP to use the phpredis extension:

echo "extension=redis.so" > /etc/php/7.4/mods-available/redis.ini
ln -s /etc/php/7.4/mods-available/redis.ini /etc/php/7.4/fpm/conf.d/30-redis.ini >/dev/null 2>&1;
ln -s /etc/php/7.4/mods-available/redis.ini /etc/php/7.4/cli/conf.d/30-redis.ini >/dev/null 2>&1;Code language: JavaScript (javascript)

If you’re using a version other than PHP 7.4, you’ll need to change the file paths accordingly.

Once you’ve completed the configuration, restart PHP:

service php7.4-fpm restartCode language: CSS (css)

To switch over to Redis cache, edit your .env file to use the phpredis Redis client and Redis as your cache driver:

REDIS_CLIENT=phpredis
CACHE_DRIVER=redis

There’s probably an existing entry you should edit for CACHE_DRIVER; you might need to add a new entry for REDIS_CLIENT.

Thanks nam in the Laracast forums for your infinite wisdom.

Leave a Reply