Knowledge Base
0%
Beginner ~15 min sudo required

Set Up Redis as Cache and Session Store for Laravel

Install Redis, configure it for Laravel cache and sessions, and verify the connection.

0 / 4 done

Prerequisites

  • Laravel application deployed
  • Ubuntu server
1
Step 1 Command

Install Redis and PHP extension

apt install redis-server php8.3-redis -y
systemctl enable redis-server
systemctl start redis-server
redis-cli ping
2
Step 2 Command

Configure Laravel .env for Redis

# In your .env file:
# CACHE_STORE=redis
# SESSION_DRIVER=redis
# REDIS_HOST=127.0.0.1
# REDIS_PORT=6379
# REDIS_PASSWORD=null
3
Step 3 Command

Install predis (optional)

composer require predis/predis
4
Step 4 Command

Clear and verify cache

cd /var/www/html/app
php artisan config:cache
php artisan cache:clear
php artisan tinker --execute="cache()->put('test', 'ok', 60); echo cache('test');"