Skip to main content
ClassQuiz relies on several external services to function properly. This guide covers the configuration for PostgreSQL, Redis, Meilisearch, hCaptcha/reCAPTCHA, and optional services like Pixabay.

PostgreSQL Database

ClassQuiz uses PostgreSQL as its primary database for storing users, quizzes, sessions, and all application data.
DB_URL
string
required
PostgreSQL connection URL in the format:postgresql://username:password@host:port/databaseDocker default: postgresql://postgres:classquiz@db:5432/classquizStandalone example: postgresql://postgres:mysecretpassword@localhost:5432/classquiz

PostgreSQL Setup

PostgreSQL is included in the Docker Compose setup:
docker-compose.yml
db:
  image: postgres:14-alpine
  restart: always
  environment:
    POSTGRES_PASSWORD: "classquiz"
    POSTGRES_DB: "classquiz"
  volumes:
    - data:/var/lib/postgresql/data
The connection URL is pre-configured:
DB_URL=postgresql://postgres:classquiz@db:5432/classquiz
Do not change the DB_URL in Docker deployments unless you modify the database service configuration

Redis Cache

Redis is used for caching, session management, OAuth state storage, and background job queues.
REDIS
string
required
Redis connection URL in the format:redis://host:port/db?decode_responses=TrueDocker default: redis://redis:6379/0?decode_responses=TrueStandalone example: redis://localhost:6379/0?decode_responses=True
The decode_responses=True parameter is required for proper string handling
CACHE_EXPIRY
integer
default:"86400"
Default cache expiration time in seconds.Default: 86400 seconds (24 hours)

Redis Setup

Redis is included in the Docker Compose setup:
docker-compose.yml
redis:
  image: redis:alpine
  restart: always
  healthcheck:
    test: ["CMD", "redis-cli", "ping"]
Connection is pre-configured:
REDIS=redis://redis:6379/0?decode_responses=True

Meilisearch

Meilisearch provides fast, typo-tolerant search functionality for quizzes.
MEILISEARCH_URL
string
required
URL of your Meilisearch instance.Docker default: http://meilisearch:7700Standalone default: http://127.0.0.1:7700
MEILISEARCH_INDEX
string
default:"classquiz"
Name of the Meilisearch index used for storing quiz search data.

Meilisearch Setup

Meilisearch is included in the Docker Compose setup:
docker-compose.yml
meilisearch:
  image: getmeili/meilisearch:v0.28.0
  restart: always
  environment:
    MEILI_NO_ANALYTICS: "true"
  volumes:
    - meilisearch-data:/data.ms
Configuration:
MEILISEARCH_URL=http://meilisearch:7700
MEILISEARCH_INDEX=classquiz
Meilisearch indexes are automatically created and configured by ClassQuiz on first use.

Captcha Services

Protect registration and login forms from bots using hCaptcha or Google reCAPTCHA.
HCAPTCHA_KEY
string
hCaptcha secret key for server-side verification.Get your key from: hCaptcha Dashboard
RECAPTCHA_KEY
string
Google reCAPTCHA secret key for server-side verification.Get your key from: reCAPTCHA Admin Console
Both captcha services are optional. If neither is configured, captcha verification will be skipped.

hCaptcha Setup

1

Create hCaptcha account

Sign up at hCaptcha.com
2

Add your site

  1. Go to Sites
  2. Add a new site with your domain
  3. Copy the Secret Key
3

Configure ClassQuiz

HCAPTCHA_KEY=your-secret-key-here

reCAPTCHA Setup

1

Register your site

2

Configure reCAPTCHA

  1. Choose reCAPTCHA v2 (“I’m not a robot” checkbox)
  2. Add your domain
  3. Accept terms and submit
  4. Copy the Secret Key
3

Configure ClassQuiz

RECAPTCHA_KEY=your-secret-key-here

Optional Services

Pixabay API

Integrate Pixabay image search into the quiz editor.
PIXABAY_API_KEY
string
API key for Pixabay integration.Get your key from: Pixabay API Documentation
1

Create Pixabay account

Sign up at Pixabay.com
2

Get API key

Navigate to API Documentation and find your API key
3

Configure ClassQuiz

PIXABAY_API_KEY=your-api-key-here

Mapbox (Not Currently Used)

Mapbox configuration is present in the codebase but not actively used in the current version.

Complete External Services Configuration

# Database
DB_URL=postgresql://postgres:classquiz@db:5432/classquiz

# Redis
REDIS=redis://redis:6379/0?decode_responses=True
CACHE_EXPIRY=86400

# Meilisearch
MEILISEARCH_URL=http://meilisearch:7700
MEILISEARCH_INDEX=classquiz

# Captcha (optional)
HCAPTCHA_KEY=your-hcaptcha-secret
# RECAPTCHA_KEY=your-recaptcha-secret

# Optional services
PIXABAY_API_KEY=your-pixabay-key

Health Checks

Verify that external services are running correctly:
# Test connection
psql postgresql://postgres:classquiz@localhost:5432/classquiz -c "SELECT 1;"

# Check if database exists
psql -U postgres -lqt | cut -d \| -f 1 | grep -qw classquiz

Troubleshooting

Check that:
  • PostgreSQL is running: systemctl status postgresql
  • Port 5432 is not blocked by firewall
  • Connection URL is correct (host, port, username, password)
  • Database exists: psql -U postgres -l
Test connection:
psql postgresql://username:password@host:port/database
Verify:
  • Redis is running: redis-cli ping
  • Redis is listening on correct port: netstat -tlnp | grep 6379
  • No authentication is required (or correct password is provided)
  • decode_responses=True parameter is present in the URL
Common issues:
  • Meilisearch service not running
  • Incorrect MEILISEARCH_URL
  • Network connectivity issues
  • Disk space full (check Meilisearch data directory)
Check Meilisearch logs:
docker-compose logs meilisearch
Verify:
  • You’re using the Secret Key (not Site Key) in HCAPTCHA_KEY/RECAPTCHA_KEY
  • Your domain is registered in the captcha service dashboard
  • Client-side captcha is correctly implemented with the Site Key
  • No network issues preventing server-side verification

Performance Tuning

PostgreSQL

-- Increase shared buffers (recommended: 25% of RAM)
ALTER SYSTEM SET shared_buffers = '256MB';

-- Enable query planning cache
ALTER SYSTEM SET plan_cache_mode = 'auto';

-- Increase worker processes
ALTER SYSTEM SET max_worker_processes = 4;

Redis

# redis.conf
maxmemory 256mb
maxmemory-policy allkeys-lru
save ""  # Disable persistence for pure cache

Meilisearch

For large datasets, consider:
  • Increasing memory allocation
  • Using dedicated Meilisearch server
  • Configuring custom ranking rules
  • Setting up replica for high availability

Security Best Practices

Never expose database or Redis ports directly to the internet. Use firewall rules and VPCs to restrict access.
  • Use strong passwords for PostgreSQL and Redis
  • Enable SSL/TLS for database connections in production
  • Regularly backup PostgreSQL data
  • Implement Redis authentication with requirepass
  • Use Meilisearch master keys in production
  • Rotate API keys periodically
  • Monitor service logs for suspicious activity

Monitoring

Consider implementing monitoring for:
  • Database query performance (pg_stat_statements)
  • Redis memory usage and hit rates
  • Meilisearch index size and search latency
  • Connection pool utilization
  • Error rates and response times
Tools: Prometheus, Grafana, pgAdmin, RedisInsight

Next Steps

Environment Variables

Complete environment variable reference

Storage Configuration

Configure file storage backends

Build docs developers (and LLMs) love