Skip to main content
Skip to main content
🚧 Work in Progress

Environment Variables in Zerops for Laravel

Zerops manages environment variables without requiring manual .env files, enabling application deployment across different environments (development, staging, production) while keeping environment-specific configurations isolated from your code.

Read more about how environment variables work in Zerops.

Laravel Environment Variables in Zerops​

Secret Variables​

Some Laravel variables contain sensitive information that should never be exposed as plain text. Manage these using Zerops Secret Variables by:

  • Creating and managing them through the Zerops GUI
  • Defining them in a configuration file when importing a project or service (allows automatic generation)

When importing a project or service, you can define secret variables directly in your import configuration:

services:
- hostname: app
type: php-nginx@8.4
envSecrets:
APP_KEY: your-secret-key
Tip

Secret variables can be updated at any time without requiring application redeployment.

Automatic Generation During Import​

If you prefer to have certain secrets generated automatically, you can use the yaml preprocessor. This is optional and only available during import:

#yamlPreprocessor=on
services:
- hostname: app
type: php-nginx@8.4
envSecrets:
APP_KEY: <@generateRandomString(<32>)>

Runtime Variables​

These variables, defined in zerops.yml, are typically environment-specific but not sensitive.

Note

Changes to runtime variables require application redeployment to take effect.

Below is a complete working example of envVariables in zerops.yml (sourced from Laravel Jetstream recipe):

zerops.yml
run:
envVariables:
APP_LOCALE: en
APP_FAKER_LOCALE: en_US
APP_FALLBACK_LOCALE: en
APP_MAINTENANCE_DRIVER: file
APP_MAINTENANCE_STORE: database
APP_TIMEZONE: UTC
APP_URL: ${zeropsSubdomain} # References generated variable
ASSET_URL: ${APP_URL}
VITE_APP_NAME: ${APP_NAME}

# PostgreSQL connection settings
DB_CONNECTION: pgsql
DB_DATABASE: db
DB_HOST: db # References database service hostname
DB_PASSWORD: ${db_password} # References database password
DB_PORT: 5432
DB_USERNAME: ${db_user} # References database user

# S3-compatible object storage settings
AWS_ACCESS_KEY_ID: ${storage_accessKeyId}
AWS_REGION: us-east-1
AWS_BUCKET: ${storage_bucketName} # References bucket name of service 'storage'
AWS_ENDPOINT: ${storage_apiUrl}
AWS_SECRET_ACCESS_KEY: ${storage_secretAccessKey} # Safely references secret
AWS_URL: ${storage_apiUrl}/${storage_bucketName}
AWS_USE_PATH_STYLE_ENDPOINT: true
FILESYSTEM_DISK: s3

# Logging Configuration
LOG_CHANNEL: syslog
LOG_LEVEL: debug
LOG_STACK: single

# SMTP settings for email delivery
MAIL_FROM_ADDRESS: hello@example.com
MAIL_FROM_NAME: ZeropsLaravel
MAIL_HOST: mailpit # References mail service hostname
MAIL_MAILER: smtp
MAIL_PORT: 1025

# Redis-based caching and session management
BROADCAST_CONNECTION: redis
CACHE_PREFIX: cache
CACHE_STORE: redis
QUEUE_CONNECTION: redis
REDIS_CLIENT: phpredis
REDIS_HOST: valkey # References Redis service hostname
REDIS_PORT: 6379
SESSION_DRIVER: redis
SESSION_ENCRYPT: false
SESSION_LIFETIME: 120
SESSION_PATH: /

# Security Configuration
BCRYPT_ROUNDS: 12
TRUSTED_PROXIES: "*"

Let's look at variable configurations that may need additional context and where to find detailed implementation guides:

Application Configuration​

Core application settings that define your Laravel app's identity, URL structure, and environment parameters. Reference environment variables from the same service.

APP_URL: ${zeropsSubdomain} # zeropsSubdomain variable is system generated
ASSET_URL: ${APP_URL}
VITE_APP_NAME: ${APP_NAME} # APP_NAME variable was created during import (envSecrets)

Database Configuration​

Essential database connection parameters that securely reference your PostgreSQL service db by hostname and its variables - password and user.

It is safe to store DB_PASSWORD in envVariables by reference as it does not contain the sensitive value itself.

DB_HOST: db
DB_PASSWORD: ${db_password}
DB_USERNAME: ${db_user}

Read more about database management for Laravel in Zerops.

Storage Configuration​

S3-compatible object storage settings that enable efficient file handling and asset management in your Laravel application. Reference variables of Object storage service called storage.

AWS_ACCESS_KEY_ID: ${storage_accessKeyId}
AWS_REGION: us-east-1
AWS_BUCKET: ${storage_bucketName}
AWS_ENDPOINT: ${storage_apiUrl}
AWS_SECRET_ACCESS_KEY: ${storage_secretAccessKey}
AWS_URL: ${storage_apiUrl}/${storage_bucketName}
AWS_USE_PATH_STYLE_ENDPOINT: true
FILESYSTEM_DISK: s3

Read more about object storage in Zerops.

Logging Configuration​

System monitoring and debugging configuration that determines how your application tracks events and errors. Use syslog channel to access logs from Zerops Dashboard.

LOG_CHANNEL: syslog

Learn how to properly configure logging for Laravel in Zerops.

Mail Configuration​

SMTP server settings that enable your application to send emails through a dedicated mail service. Reference service mailpit by hostname.

MAIL_HOST: mailpit

Learn how to properly configure SMTP for Laravel in Zerops.

Cache and Session​

Redis-based configuration for handling application caching, queues, and session management to optimize performance. Reference service valkey by hostname.

REDIS_HOST: valkey

Learn how to properly configure cache, queue & session management for Laravel in Zerops.

Tip

For automatic execution with each deploy, add these commands to the initCommands section of your zerops.yml file.

zerops.yml
initCommands:
- php artisan view:cache
- php artisan config:cache
- php artisan route:cache