diff --git a/README.md b/README.md index 16d9e36..b40fbe0 100644 --- a/README.md +++ b/README.md @@ -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. + +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 `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). +Update `development.env` with your local environment variables overrides. 2) Apache diff --git a/backend.dockerfile b/backend.dockerfile index 117b1e0..177094a 100644 --- a/backend.dockerfile +++ b/backend.dockerfile @@ -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} diff --git a/backend/config/application.php b/backend/config/application.php index 53daba9..e12625e 100644 --- a/backend/config/application.php +++ b/backend/config/application.php @@ -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_'; diff --git a/backend/config/environments/development.php b/backend/config/environments/development.php index 528be4a..5dd04a1 100644 --- a/backend/config/environments/development.php +++ b/backend/config/environments/development.php @@ -1,7 +1,25 @@ load(); + $dotenv->required(['MYSQL_DATABASE', 'MYSQL_USER', 'MYSQL_PASSWORD']); +} \ No newline at end of file diff --git a/backend/config/environments/local.php b/backend/config/environments/local.php deleted file mode 100644 index 3f10e20..0000000 --- a/backend/config/environments/local.php +++ /dev/null @@ -1,16 +0,0 @@ -load(); - $dotenv->required(['MYSQL_DATABASE', 'MYSQL_USER', 'MYSQL_PASSWORD', 'WP_HOME']); -} \ No newline at end of file diff --git a/backend/config/environments/staging.php b/backend/config/environments/staging.php new file mode 100644 index 0000000..528be4a --- /dev/null +++ b/backend/config/environments/staging.php @@ -0,0 +1,7 @@ +