Skip to main content
Spree uses environment variables for all deployment configuration. No secrets or credentials are stored in the codebase.

Required

These two variables are all a production deployment strictly needs: You’ll almost always want to set RAILS_HOST too — without it, generated URLs point at localhost, and the three Active Record encryption keys — without them, secrets Spree stores are kept in plain text.

Active Record encryption

Spree encrypts sensitive values at rest with Active Record encryption: payment gateway and integration secrets (API keys and webhook signing secrets), webhook endpoint signing secrets, payment gateway customer IDs, and the OAuth tokens stored on user identities. It does so only when encryption keys are configured — without them, these values are stored in plain text and a production app logs a warning at boot. Set all three. Each is a random string — generate a set with any of:
  • New projects — create-spree-app generates the keys into .env, and the Render Blueprint generates them for production.
  • Production — use a separate set of keys from development and store it in your secret manager as a backup.
  • Rails credentials — instead of env vars, you can put the values printed by bin/rails db:encryption:init under active_record_encryption in your encrypted credentials. When both are present, the env vars win.
Never change or lose the keys once data is encrypted — records encrypted with them become unreadable. Rails supports rotating the primary key by adding the new key and keeping the old one, but it doesn’t support rotating the deterministic key — and webhook endpoint secrets and gateway customer IDs are encrypted deterministically. Keep ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY and ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT unchanged unless you plan a migration that re-encrypts those records.

Enabling encryption on an existing installation

Records written before the keys were set are stored in plain text. OAuth tokens on user identities stay readable and are encrypted on their next write. Webhook endpoint secrets and gateway customer IDs are not readable in plain text once encryption is on, so enable encryption with plaintext support first, then encrypt the existing rows:
  1. Allow reading and looking up plaintext rows in config/application.rb:
  2. Set the three keys (see above) and deploy.
  3. Encrypt the existing rows from a Rails console (spree console or bin/rails console):
  4. Remove the two settings from step 1 and deploy again.
Apps created from an older spree-starter also need config/application.rb to read the env vars — see the 5.6 to 6.0 upgrade guide.

URLs and Hosts

RAILS_HOST is the canonical public host of your deployment. URLs Spree generates outside a request context use it — links in emails, webhook payloads, and image/attachment URLs in API responses (for the latter, CDN_HOST takes precedence when set).
When neither RAILS_HOST nor CDN_HOST is configured, image and attachment URLs fall back to the store’s URL setting, which is localhost on a fresh install — API responses will contain https://localhost/... URLs.
Generated URLs use https unless both RAILS_FORCE_SSL and RAILS_ASSUME_SSL are set to false (see SSL).

Web Server

Background Jobs

Background jobs (emails, image processing, webhooks, imports) run inside the web container by default — no extra service needed. See Background Jobs for how this works and when to split out a dedicated worker.

Email (SMTP)

This configuration powers all emails Spree sends — customer transactional emails (order confirmation, shipping notification; on by default) and staff notifications. A storefront can optionally take over customer emails via webhooks — see Emails.
Spree works with any SMTP provider (Resend, Postmark, Mailgun, SendGrid, Amazon SES, etc.). Set SMTP_HOST to enable email delivery — when not set, production email delivery is disabled (in development, emails are captured by Mailpit at http://localhost:8025 instead of being sent). See Emails for the full guide. Links in emails use the host configured via RAILS_HOST.

Application

File Storage (S3 / Cloudflare R2)

By default, uploaded files (product images, assets) are stored on the local filesystem. Set the appropriate credentials to use cloud storage instead — Spree auto-detects the provider based on which credentials are present. See Asset Storage for the full guide.

Amazon S3

Cloudflare R2

Search (Meilisearch)

Optional. When configured, Spree uses Meilisearch for product search, filtering, and faceted navigation instead of SQL. After setting these, add the spree_meilisearch gem, enable the provider and reindex:

Error Tracking (Sentry)

SSL

By default, Spree assumes it runs behind an SSL-terminating reverse proxy or load balancer. Set these to false if running without SSL (e.g., local development or behind a proxy that doesn’t do SSL termination).

Local Development

These variables are used when running the server/ app locally (not via DATABASE_URL):