All Projects → studio24 → Wordpress Multi Env Config

studio24 / Wordpress Multi Env Config

WordPress Multi-Environment Config

Projects that are alternatives of or similar to Wordpress Multi Env Config

Awesome Wp Cli
A curated list of packages and resources for WP-CLI, the command-line interface for WordPress.
Stars: ✭ 129 (-82.64%)
Mutual labels:  wp-cli, wordpress
Wplib Box
The Best Local Dev Server for WordPress Developers
Stars: ✭ 204 (-72.54%)
Mutual labels:  wp-cli, wordpress
Image Optimize Command
Easily optimize images using WP CLI
Stars: ✭ 138 (-81.43%)
Mutual labels:  wp-cli, wordpress
Pilothouse
A command line app for managing a LEMP local development environment based on Docker.
Stars: ✭ 98 (-86.81%)
Mutual labels:  wp-cli, wordpress
Airplane Mode
Disables external data calls and loading for working on a purely local (i.e. no internet connection) WordPress site
Stars: ✭ 441 (-40.65%)
Mutual labels:  wp-cli, wordpress
Wordup Cli
Wordup is a fully integrated development platform for WordPress. Develop plugins and themes locally. Preview in the cloud. Automatic updates in WP.
Stars: ✭ 116 (-84.39%)
Mutual labels:  wp-cli, wordpress
Trellis
WordPress LEMP stack with PHP 8.0, Composer, WP-CLI and more
Stars: ✭ 2,295 (+208.88%)
Mutual labels:  wp-cli, wordpress
Wp Cli Replicator
Replicate production websites from WordPress eXtended RSS (WXR) export files
Stars: ✭ 34 (-95.42%)
Mutual labels:  wp-cli, wordpress
Cavalcade
A better wp-cron. Horizontally scalable, works perfectly with multisite.
Stars: ✭ 412 (-44.55%)
Mutual labels:  wp-cli, wordpress
Stream
🗄️ Stream plugin for WordPress
Stars: ✭ 335 (-54.91%)
Mutual labels:  wp-cli, wordpress
Ext
WP-CLI command which checks the existence of PHP extensions needed to run WordPress.
Stars: ✭ 69 (-90.71%)
Mutual labels:  wp-cli, wordpress
Wp Cli
⚙️ WP-CLI framework
Stars: ✭ 4,474 (+502.15%)
Mutual labels:  wp-cli, wordpress
Wp Cli Fixtures
Easily generate custom fake data for WordPress
Stars: ✭ 65 (-91.25%)
Mutual labels:  wp-cli, wordpress
Docker Compose Wordpress
An example Docker Compose setup for WordPress plugin or theme development.
Stars: ✭ 127 (-82.91%)
Mutual labels:  wp-cli, wordpress
Vccw
A Vagrant based development environment.
Stars: ✭ 1,012 (+36.2%)
Mutual labels:  wp-cli, wordpress
Docker Wordpress
WordPress container with Nginx 1.16 & PHP-FPM 7.3 based on Alpine Linux
Stars: ✭ 148 (-80.08%)
Mutual labels:  wp-cli, wordpress
Wordpress To Jekyll Exporter
One-click WordPress plugin that converts all posts, pages, taxonomies, metadata, and settings to Markdown and YAML which can be dropped into Jekyll
Stars: ✭ 951 (+27.99%)
Mutual labels:  wp-cli, wordpress
Wp Vps Build Guide
A verbose build guide for a modern, high-performance WordPress production VPS.
Stars: ✭ 31 (-95.83%)
Mutual labels:  wp-cli, wordpress
config-command
Generates and reads the wp-config.php file.
Stars: ✭ 32 (-95.69%)
Mutual labels:  config, wp-cli
Wordpress Nginx Docker Compose
Run WordPress with nginx using Docker Compose.
Stars: ✭ 460 (-38.09%)
Mutual labels:  wp-cli, wordpress

Studio 24 WordPress Multi-Environment Config

This repository contains Studio 24's standard config setup for WordPress, which loads different config based on current environment. This allows you to have different site configuration (e.g. debug mode) for different environments (e.g. production and staging).

Credit is due to FocusLabs EE Master Config who gave me the inspiration for the organisation of the config files.

Please note the current version is v2, if you need to use the older v1 version please see the v1 release.

How it works

The system detects what environment the current website is in and loads the relevant config file for that environment.

By default the environment is defined by the hostname, though you can also set this as an environment variable.

Config files are then loaded according to the current environment. There is support for loading a local config file for sensitive data, which is intended to not be committed to version control.

Config files

Up to three different config files are loaded:

  1. Default configuration (in wp-config.default.php, e.g. shared settings such as $table_prefix)
  2. Environment configuration (in wp-config.{ENVIRONMENT}.php, e.g. any setting specific to the environment such as database name or debug mode)
  3. Optional local settings (in wp-config.local.php, e.g. any sensitive settings you do not want to commit to version control, e.g. database password)

Environment values

By default, environment values are:

  • production (live website)
  • staging (test website for client review)
  • development (local development copy of the website)

You can add other environment values by adding these to the wp-config.env.php file.

Setting the environment

The current environment is detected in one of three ways:

Environment variable

You can set an environment variable called WP_ENV to set which environment the website uses in your webserver configuration.

This is commonly done via Apache in your virtual host declaration:

SetEnv WP_ENV production

If you don't use Apache consult your webserver documentation.

Server hostname

The current environment can also be detected from matching the hostname with the domain setup in wp-config.env.php.

WP-CLI

If you're using WP-CLI you can specify your environment using an '.env' file.

You need to create a file called .env and simply write the current environment in this file as a string.

Example:

development

This file needs to be placed among the wp-config.*.php files (this applies if you keep these files in a sub-folder and the wp-config.php file in the web root).

It is recommended you do not add this file to version control.

The wp-config.env.php file

You need to edit the wp-config.env.php file to define some settings related to the current environment URL. This needs to be set regardless of which method is used to set the environment, since all methods set the WordPress URL via settings contained in this file.

This file contains a simple array, made up of:

environment names =>
    domain  => The domain name.
               This can also be an array of multiple domains.
               You can also use a wildcard * to indicate all sub-domains at a domain, which is useful when using
               WordPress Multisite. If you use wildcards, set the domain should to a single string, not an array.
    path    => If WordPress is installed to a sub-folder set it here.
    ssl     => Whether SSL should be used on this domain. If set, this also sets FORCE_SSL_ADMIN to true.

Example usage:

$env = [
    'production'  => [
        'domain' => 'domain.com',
        'path'   => '',
        'ssl'    => false,
    ],
    'staging'     => [
        'domain' => 'staging.domain.com',
        'path'   => '',
        'ssl'    => false,
    ],
    'development' => [
        'domain' => 'domain.local',
        'path'   => '',
        'ssl'    => false,
    ],
];

If you use localhost for your local test website, just set the development hostname case to localhost rather than domain.local.

Example usage when setting a sub-folder, and also serving the live site via SSL:

    'production'  => [
        'domain' => 'domain.com',
        'path'   => 'blog',
        'ssl'    => true,
    ],

Example usage for using more than one domain for an environment.

    'production'  => [
        'domain' => ['domain.com', 'domain2.com'],
        'path'   => '',
        'ssl'    => false,
    ],

Example usage when using a wildcard for WordPress multi-site.

    'production'  => [
        'domain' => '*.domain.com',
        'path'   => '',
        'ssl'    => false,
    ],

Installing

Please note this requires PHP5.4 or above. You should really be on PHP5.6 at a minimum!

  1. First make a backup of your existing wp-config.php file.
  2. Copy the following files from this repository to your WordPress installation:
wp-config.default.php
wp-config.env.php
wp-config.php
wp-config.load.php
  1. Set the correct environments you wish to support via the file wp-config.env.php, see the documentation above.
  2. Create one wp-config.{environment}.php file for each environment. You can use the sample files provided in this repository:
wp-config.development.php
wp-config.production.php
wp-config.staging.php
wp-config.local.php
  1. Review your backup wp-config.php file and copy config settings to either the default config file or the environment config files as appropriate. It is suggested to:
    • If the setting is the same across all environments, add to wp-config.default.php
    • If the setting is unique to one environment, add to wp-config.{environment}.php
    • If the setting is sensitive (e.g. database password) add to wp-config.local.php
  2. Remember to update the authentication unique keys and salts in wp-config.default.php
  3. If you use version control exclude wp-config.local.php, an example below for Git:
# .gitignore
wp-config.local.php

You should now be able to load up the website in each different environment and everything should work just fine! It should now be safe to delete your backup wp-config.php file.

Moving your config files outside of the document root

If you want to store your config files outside of the document root for additional security, this is very easy.

Simply move all the config files except for wp-config.php itself into another folder (which can be outside the doc root). Next amend the require path for wp-config.load.php in wp-config.php to point to the new location and everything will work just fine!

Example directory structure:

config/
       wp-config.default.php   (Config folder outside of doc root)
       wp-config.development.php
       wp-config.env.php
       wp-config.load.php
       wp-config.local.php
       wp-config.production.php
       wp-config.staging.php
web/
    wp-config.php              (Your website doc root, where WordPress is installed) 

Example wp-config.php

/** Load the Studio 24 WordPress Multi-Environment Config. */
require_once(ABSPATH . '../config/wp-config.load.php');
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].