This commit is contained in:
Almira Krdzic
2018-07-30 17:26:55 +02:00
parent 828c71c253
commit 0ac5e5940b
7 changed files with 48 additions and 42 deletions

View File

@@ -22,9 +22,8 @@ Wiaas implementation based on wordpress [woocommerce](https://woocommerce.com/)
* `MYSQL_DATABASE` - Wordpress database name
* `MYSQL_USER` - Wordpress database user
* `MYSQL_PASSWORD` - Wordpress database password
* `MYSQL_HOST` - Wordpress database host (will be `db` for docker)
* `WP_ENV` - Set to environment (`local`, `development`, `production`)
* `API_URL` - Full URL to WordPress home (http://localhost:8081 if you are testing locally)
* `WP_ENV` - Set to environment (`development`, `staging`, `production`)
* `WP_AUTH_KEY`, `WP_SECURE_AUTH_KEY`, `WP_LOGGED_IN_KEY`, `WP_NONCE_KEY`, `WP_AUTH_SALT`, `WP_SECURE_AUTH_SALT`, `WP_LOGGED_IN_SALT`, `WP_NONCE_SALT`, `WP_JWT_AUTH_SECRET_KEY`
3) Execute in the root of the project :
@@ -53,14 +52,16 @@ Frontend is running on http://localhost:8080 and backend on http://localhost:808
1) Environment variables
For handling environment variables during local development we use [dotenv](https://github.com/vlucas/phpdotenv) library which will load all variables from `local.env` file
if such file is present. These variables will then be accessible inside wordpress.
cp environment.env local.env
For handling wordpress environment variables during local development we use [dotenv](https://github.com/vlucas/phpdotenv) library
which enables loading variables from `.env` file.
Update `local.env` with your local environment variables.
Remember to uncomment env variables needed for local wordpress development like WP_HOME and WP_DB_HOST.
(important: set WP_ENV to local only for local coding environment, since it will activate script debug, wordpress debug and save query options).
If you wish to keep your docker and development setup different then generate `development.env` file which will then
be loaded by dotenv insted of default `.env` file.
cp environment.env development.env
Update `development.env` with your local environment variables overrides.
2) Apache

View File

@@ -19,6 +19,7 @@ ARG WP_JWT_AUTH_SECRET_KEY
ENV WP_ENV ${WP_ENV}
ENV WP_HOME ${API_URL}
ENV WP_DB_HOST db
ENV MYSQL_DATABASE ${MYSQL_DATABASE}
ENV MYSQL_USER ${MYSQL_USER}

View File

@@ -15,7 +15,7 @@ Env::init();
* Set up our global environment constant and load its config first
* Default: development
*/
define('WP_ENV', env('WP_ENV') ?: 'local');
define('WP_ENV', env('WP_ENV') ?: 'development');
$env_config = __DIR__ . '/environments/' . WP_ENV . '.php';
@@ -26,7 +26,7 @@ if (file_exists($env_config)) {
/**
* URLs
*/
define('WP_HOME', env('WP_HOME'));
define('WP_HOME', env('WP_HOME') ?: 'http://localhost');
define('WP_SITEURL', WP_HOME . '/wp');
/**
@@ -43,7 +43,7 @@ define('VP_PROJECT_ROOT', $webroot_dir . '/wp/');
define('DB_NAME', env('MYSQL_DATABASE'));
define('DB_USER', env('MYSQL_USER'));
define('DB_PASSWORD', env('MYSQL_PASSWORD'));
define('DB_HOST', env('WP_DB_HOST') ?: 'db');
define('DB_HOST', env('WP_DB_HOST') ?: 'localhost');
define('DB_CHARSET', 'utf8mb4');
define('DB_COLLATE', '');
$table_prefix = env('DB_PREFIX') ?: 'wp_';

View File

@@ -1,7 +1,25 @@
<?php
/** Development */
ini_set('display_errors', 0);
define('WP_DEBUG_DISPLAY', false);
define('SCRIPT_DEBUG', false);
/** Disable all file modifications including updates and update notifications */
define('DISALLOW_FILE_MODS', true);
define('SAVEQUERIES', true);
define('WP_DEBUG', true);
define('SCRIPT_DEBUG', true);
/**
* Use Dotenv to set required environment variables and load .local.env file
*/
$dotenv_dir = dirname(dirname(dirname(__DIR__)));
$env_file_name = null;
if (file_exists($dotenv_dir . '/development.env')) {
$env_file_name = 'development.env';
} else if(file_exists($dotenv_dir . '/.env')) {
$env_file_name = '.env';
}
if (isset($env_file_name)) {
$dotenv = new Dotenv\Dotenv($dotenv_dir, $env_file_name);
$dotenv->load();
$dotenv->required(['MYSQL_DATABASE', 'MYSQL_USER', 'MYSQL_PASSWORD']);
}

View File

@@ -1,16 +0,0 @@
<?php
/** Development */
define('SAVEQUERIES', true);
define('WP_DEBUG', true);
define('SCRIPT_DEBUG', true);
/**
* Use Dotenv to set required environment variables and load .env file in root if on local
*/
$dotenv_dir = dirname(dirname(dirname(__DIR__)));
$dotenv = new Dotenv\Dotenv($dotenv_dir, 'local.env');
if (file_exists($dotenv_dir . '/local.env')) {
$dotenv->load();
$dotenv->required(['MYSQL_DATABASE', 'MYSQL_USER', 'MYSQL_PASSWORD', 'WP_HOME']);
}

View File

@@ -0,0 +1,7 @@
<?php
/** Development */
ini_set('display_errors', 0);
define('WP_DEBUG_DISPLAY', false);
define('SCRIPT_DEBUG', false);
/** Disable all file modifications including updates and update notifications */
define('DISALLOW_FILE_MODS', true);

View File

@@ -4,22 +4,17 @@ MYSQL_DATABASE=wordpress
MYSQL_USER=wp_admin
MYSQL_PASSWORD=wp_password
API_URL=url
# Url where backend application api is available
API_URL=http://localhost
#Wordpress config
# Determines loading of enviroment specific non sensitive wordpress config file (/backend/config/environments/[WP_ENV].php)
# Set this to local only for local wordpress development (it will activate WP_DEBUG, SCRIPT_DEBUG and SAVEQUERIES)
# Possible values [development, staging, production]
# Note that development value will activate WP_DEBUG, SCRIPT_DEBUG and SAVEQUERIES
WP_ENV=development
# Required for local wordpress development only for quick override of default db if needed
#WP_DB_HOST=localhost
# Required for local wordpress development since dotenv allows this kind of initialization
# For docker deployment this is done inside docker container
#WP_HOME=${API_URL}
# Generate salts here https://api.wordpress.org/secret-key/1.1/salt/
WP_AUTH_KEY=generate_me
WP_SECURE_AUTH_KEY=generate_me
WP_LOGGED_IN_KEY=generate_me