Environment Variables

The .env file is where we define the environment variables that are used to configure both Docker and the WordPress installation.

This keeps sensitive configuration information out of repositories and public web directories, and allows for quick and easy configuration.

The .env and wp-config-env.php files are located one level above the public web root (app directory).

The repository contains 2 example .env files:

  • .env.dev: Example development defaults.

  • .env.prod: Example production defaults.

ENVIRONMENT VARIABLES

The following environment variables are used in ./docker-compose.yml: D = Docker W = WordPress

Project & Environment

COMPOSE_PROJECT_NAME (D)

  • Must be unique to this project when used on a host with other Boilerplate projects.

  • Used to avoid Docker conflicts

  • Each Docker container is prefixed with this name

  • Make it something you won't mind typing in a terminal. Make it meaningful.

  • Default: rdbi

ENVIRONMENT (W)

  • Used to enable/disable development features such as enabling WP_DEBUG and the Query Monitor Plugin. development and production are valid.

  • Disables Analytics tags in development environments

  • Default: development

Directories (WP Codex)

WP_CONTENT_URL

  • Default: http://localhost/lib

WP_CONTENT_DIR

  • Default: /var/www/html/app/lib

WP_HOME

  • Default: http://localhost

WP_SITEURL

  • Default: http://localhost/core

Database

DB_NAME (D,W)

  • Same as DB_NAME in wp-config.php

  • Default: default

DB_HOST (D,W)

  • Same as DB_HOST in wp-config.php

  • Default: localhost

DB_USER (D,W)

  • Same as DB_USER in wp-config.php

  • Default: default

DB_PASSWORD (D,W)

  • Same as DB_PASSWORD in wp-config.php

  • Default: secret

DB_CHARSET (W)

  • Same as DB_CHARSET in wp-config.php

  • Default: utf8mb4

TABLE_PREFIX (W)

  • Sets the table prefix.

  • Default: wp_

WordPress Core

AUTO_UPDATE_CORE (WP Codex)

  • Disable WordPress core updates

  • Default: false

DISALLOW_FILE_EDIT (WP Codex)

  • Disable file editing in the WordPress admin panel.

  • Default: false

  • Forces a file system method. Useful for some hosts.

  • Default: ''

Customizer

ENABLE_CUSTOMIZER_SITE_ID_ADDITIONS

  • Adds more business identity fields to the customizer in the existing "Site Identity" section.

  • Default false

  • Further info: SiteIdentity

ENABLE_CUSTOMIZER_ANALYTICS

  • Adds Analytics section to the customizer.

  • Contains a field for a Google Tracking ID.

  • Enables tracking script in footer for production environment only.

  • Can be extended to contain other analytics related fields.

ENABLE_CUSTOMIZER_OPEN_GRAPH

  • Adds Open Graph fields to the customizer:

    • Title

    • Description

    • Type

    • URL

    • Image

Dashboard Meta (WP Codex)

REMOVE_DEFAULT_DASHBOARD_META

  • Removes the following meta boxes from the dashboard.

    • dashboard_incoming_links

    • dashboard_plugins

    • dashboard_primary

    • dashboard_secondary

    • dashboard_quick_press

    • dashboard_recent_drafts

    • dashboard_recent_comments

    • dashboard_right_now

    • dashboard_activity

  • Default false

ENABLE_SUPPORT_WIDGET

  • Enable the Support Widget on the Dashboard

  • Default: true

SW_DEVELOPER_NAME

  • Set the Developer Name for the Support Widget

  • Default: "Your Name"

SW_DEVELOPER_PHONE

  • Set the Developer Phone for the Support Widget

  • Default: "555-555-1212"

SW_DEVELOPER_EMAIL

  • Set the Developer Email for the Support Widget

  • Default: "you@test.com"

Dashboard Menu (WP Codex)

REMOVE_POSTS_MENU

  • Remove the Posts menu

  • Default false

REMOVE_MEDIA_MENU

  • Remove the Media menu

  • Default false

REMOVE_PAGES_MENU

  • Remove the Pages menu

  • Default false

REMOVE_COMMENTS_MENU

  • Remove the Comments menu from the Dashboard

  • Default false

REMOVE_APPEARANCE_MENU

  • Remove the Appearance menu from the Dashboard

  • Default false

REMOVE_PLUGINS_MENU

  • Remove the Plugins menu from the Dashboard

  • Default false

REMOVE_USERS_MENU

  • Remove the Users menu from the Dashboard

  • Default false

REMOVE_TOOLS_MENU

  • Remove the Tools menu from the Dashboard

  • Default false

REMOVE_SETTINGS_MENU

  • Remove the Settings menu from the Dashboard

  • Default false`

Advanced Custom Fields (ACF)

INIT_ACF

  • Loads ACF.

  • Default: false

REMOVE_ACF_MENU

  • Hides the ACF menu from the Dashboard

  • Requires INIT_ACF to be true

  • Default: false

Admin Bar

SHOW_ADMIN_BAR

  • Toggle display of the front-end admin bar.

  • Default: true

Debug

DEBUG_ACTIVE

  • Used to set Debug Mode to active.

  • Default: false

FORCE_DEBUG

  • Used to force Debug Mode when ENVIRONMENT is set to production

  • Default: false

ENABLE_DEBUG_BAR

ENABLE_QUERY_MONITOR

How Debug Mode Works

It's pretty simple, here's what I'm doing:

// Define the environment constant from .env, or default to development.
define('ENVIRONMENT', getenv('ENVIRONMENT' ?: 'development'));
/**
* Allow debug tools if:
* ENVIRONMENT = development & DEBUG_ACTIVE = true
* or:
* ENVIRONMENT = production & DEBUG_ACTIVE = true & DEBUG_FORCE = iKnowWhatImDoing
*/
if ((
// Development environment & debug active.
ENVIRONMENT === 'development' &&
getenv('DEBUG_ACTIVE') === 'true'
)||(
// Production environment & debug active & debug force active.
ENVIRONMENT === 'production' &&
getenv('DEBUG_ACTIVE') === 'true' &&
getenv('DEBUG_FORCE') === 'iKnowWhatImDoing'
)
) :
// Debug Mode on.
define('WP_DEBUG', true);
define('WP_DEBUG_DISPLAY', true);
@ini_set('display_errors', 1);
define('ENABLE_DEBUG_BAR', getenv('ENABLE_DEBUG_BAR') ?: 'false');
define('ENABLE_QUERY_MONITOR', getenv('ENABLE_QUERY_MONITOR') ?: 'false');
else :
// Debug Mode off.
define('WP_DEBUG', false);
define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors', 0);
define('ENABLE_DEBUG_BAR', 'false');
define('ENABLE_QUERY_MONITOR', 'false');
endif;

DISABLE_WP_CRON

  • It's been pointed out to me that wp-cron was causing server response issues in development. I've sort of confirmed that disabling wp-cron in development improves response time. I haven't had much of a reason to look into it further. Here's a toggle.

  • Default: false