Environment Keys

The Env class loads configuration values from your .env file. Below are the key environment variables used by Stilmark Base.

Base Configuration

Core configuration variables that control Base framework behavior:

# Base config
APP_ENV=local
SERVER_NAME=base.dev
AUTH_SESSION_NAME=auth
CONTROLLER_NS=BaseApp\Controller\\
ROUTES_PATH=/app/routes.php
ROUTES_CACHE_PATH=/cache/routes.cache.php

Base Config Variables

Variable
Description
Default
Example

APP_ENV

Application environment (local, development, production)

local

production

APP_DEBUG

Enable debug mode (shows errors, stack traces, etc.)

true in local/development, false otherwise

true

SERVER_NAME

Server hostname for the application

base.dev

myapp.com

SESSION_AUTH_NAME

Session name for authentication

auth

myapp_auth

CONTROLLER_NS

Namespace for controllers

BaseApp\Controller\

App\Controllers\

ROUTES_PATH

Path to routes configuration file

/app/routes.php

/config/routes.php

ROUTES_CACHE_PATH

Path for cached routes

/cache/routes.cache.php

/tmp/routes.cache

Session Configuration

Variable
Description
Default
Example

SESSION_DRIVER

Session storage driver

file

file, redis

SESSION_LIFETIME

Session lifetime in minutes

120

1440 (24 hours)

SESSION_SECURE_COOKIE

Only send cookie over HTTPS

false

true in production

SESSION_HTTP_ONLY

Make cookie accessible only through HTTP

true

true

SESSION_SAME_SITE

CSRF protection level

Lax

Strict, Lax, None

SESSION_SAVE_PATH

Path for file-based sessions

System temp dir

/path/to/sessions

Geolocation & Localization

Localization Variables

Variable
Description
Default
Example

LOCALE

System locale setting

en_US.UTF8

da_DK.UTF8

TIMEZONE

Default timezone

Europe/Copenhagen

America/New_York

TIME_STANDARD

Time standard abbreviation

CET

EST

Database Configuration

Database Variables

Variable
Description
Default
Example

DB_HOST

Database server hostname

localhost

db.example.com

DB_DATABASE

Database name

baseapp

myapp_production

DB_USERNAME

Database username

local

app_user

DB_PASSWORD

Database password

local

secure_password

Authentication

Google OAuth2 configuration for authentication:

OAuth Variables

Variable
Description
Required
Example

GOOGLE_CLIENT_ID

Google OAuth2 client ID

Yes

123456789-abc.apps.googleusercontent.com

GOOGLE_CLIENT_SECRET

Google OAuth2 client secret

Yes

GOCSPX-abcdefghijklmnop

GOOGLE_REDIRECT_URI

OAuth callback URI

Yes

https://myapp.com/auth/google/callback

CORS Configuration

Cross-Origin Resource Sharing (CORS) configuration for handling requests from different domains:

CORS Variables

Variable
Description
Default
Example

CORS_ENABLED

Enable/disable CORS handling

false

true

CORS_ALLOWED_ORIGINS

Comma-separated list of allowed origins

(empty)

https://app.com,https://admin.app.com

CORS_ALLOWED_METHODS

HTTP methods allowed for CORS requests

GET, POST, PUT, DELETE, OPTIONS

GET, POST, OPTIONS

CORS_ALLOWED_HEADERS

Headers allowed in CORS requests

Content-Type, Authorization, X-Requested-With

Content-Type, X-API-Key

CORS_ALLOW_CREDENTIALS

Allow credentials (cookies, auth headers)

false

true

CORS_MAX_AGE

Preflight cache duration in seconds

86400

3600

CORS Origin Patterns

You can specify origins in several ways:

Environment-Specific Configuration

Development Environment

Production Environment

Testing Environment

Custom Application Variables

You can define your own keys in .env for application-specific configuration:

Accessing Variables in Code

Environment Validation

Validate required environment variables on application startup:

Security Best Practices

  1. Never commit .env files to version control

  2. Use strong passwords for database and API keys

  3. Rotate secrets regularly in production environments

  4. Use environment-specific files (.env.local, .env.production)

  5. Validate required variables during application bootstrap

  6. Use HTTPS for OAuth redirect URIs in production

Last updated