Lesson 2
20 min
Free Preview
Installing Redis
Install and configure Redis on various platforms.
Installing Redis
Redis can be installed on virtually any system. This covers Linux, Docker, and cloud platforms.
💡 Recommendation
For development, use Docker. For production, use managed Redis or install on Linux.
Docker Installation (Recommended)
# Pull and run Redis with persistence
docker run -d \
--name redis \
-p 6379:6379 \
-v redis-data:/data \
redis:alpine redis-server --appendonly yes
# Connect to Redis
docker exec -it redis redis-cli
# With RedisInsight GUI
docker run -d \
--name redis-stack \
-p 6379:6379 \
-p 8001:8001 \
redis/redis-stack:latest
# Access GUI at http://localhost:8001
Ubuntu/Debian Installation
# Install Redis
sudo apt update
sudo apt install redis-server -y
# Enable and start
sudo systemctl enable redis-server
sudo systemctl start redis-server
# Test
redis-cli ping
# PONG
Configuration
# /etc/redis/redis.conf
# Network (security!)
bind 127.0.0.1
# Password
requirepass YourSecurePassword123!
# Memory limit
maxmemory 256mb
maxmemory-policy allkeys-lru
# Persistence
appendonly yes
PHP Connection
<?php
// Install: composer require predis/predis
require 'vendor/autoload.php';
$redis = new Predis\Client([
'scheme' => 'tcp',
'host' => '127.0.0.1',
'port' => 6379,
'password' => 'YourSecurePassword123!'
]);
echo $redis->ping(); // PONG
$redis->set('name', 'John');
echo $redis->get('name'); // John
Verify Installation
# Check version
redis-server --version
# Server info
redis-cli INFO server
# Memory usage
redis-cli INFO memory
# Monitor commands
redis-cli MONITOR
Useful Resources
🚀 Next Steps
In the next lesson, you'll master Redis data types.