Skip to content

Commit 7c9b5ad

Browse files
committed
Allow env vars to control wp-config.php settings
Before: all our wp-config.php settings were hardcoded Now: we provide defaults, but allow them to be over-ridden by env vars.
1 parent 1ad932e commit 7c9b5ad

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

images/wordpress/wp-config.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,53 @@
1212

1313
// For some reason this is not being set correctly by default
1414
if (!defined('DB_CHARSET')) {
15-
define('DB_CHARSET', 'utf8mb4');
15+
define('DB_CHARSET', $_ENV['DB_CHARSET'] ?? 'utf8mb4');
1616
}
1717

1818
// Set URLs if they aren't set already
1919
$host = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost';
2020
if (!defined('WP_SITEURL')) {
21-
define('WP_SITEURL', 'http://'.$host);
21+
define('WP_SITEURL', $_ENV['WP_SITEURL'] ?? 'http://'.$host);
2222
}
2323
if (!defined('WP_HOME')) {
24-
define('WP_HOME', 'http://'.$host);
24+
define('WP_HOME', $_ENV['WP_HOME'] ?? 'http://'.$host);
2525
}
2626

2727
// beanstalk
28-
define('BEANSTALKD_HOST', 'beanstalk');
28+
define('BEANSTALKD_HOST', $_ENV['BEANSTALKD_HOST'] ?? 'beanstalk');
2929

3030
// mu-plugins
31-
define('WPMU_PLUGIN_DIR', '/usr/src/mu-plugins');
31+
define('WPMU_PLUGIN_DIR', $_ENV['WPMU_PLUGIN_DIR'] ?? '/usr/src/mu-plugins');
3232

3333
// Database
34-
define('DB_HOST', 'mysql:3306');
35-
define('DB_NAME', 'wordpress');
36-
define('DB_USER', 'root');
37-
define('DB_PASSWORD', 'foobar');
34+
define('DB_HOST', $_ENV['DB_HOST'] ?? 'mysql:3306');
35+
define('DB_NAME', $_ENV['DB_NAME'] ?? 'wordpress');
36+
define('DB_USER', $_ENV['DB_USER'] ?? 'root');
37+
define('DB_PASSWORD', $_ENV['DB_PASSWORD'] ?? 'foobar');
3838

3939
// wp-config stuff
4040

4141
if (!defined('WP_DEBUG')) {
42-
define('WP_DEBUG', false);
42+
define('WP_DEBUG', $_ENV['WP_DEBUG'] ?? false);
4343
}
44-
define('WP_DEBUG_DISPLAY', true);
45-
define('WP_ALLOW_MULTISITE', true);
46-
define('FS_METHOD', 'direct');
47-
define('CORE_UPGRADE_SKIP_NEW_BUNDLED', true);
44+
define('WP_DEBUG_DISPLAY', $_ENV['WP_DEBUG_DISPLAY'] ?? true);
45+
define('WP_ALLOW_MULTISITE', $_ENV['WP_ALLOW_MULTISITE'] ?? true);
46+
define('FS_METHOD', $_ENV['FS_METHOD'] ?? 'direct');
47+
define('CORE_UPGRADE_SKIP_NEW_BUNDLED', $_ENV['CORE_UPGRADE_SKIP_NEW_BUNDLED'] ?? true);
4848

49-
define('AUTH_KEY', 'put your unique phrase here');
50-
define('SECURE_AUTH_KEY', 'put your unique phrase here');
51-
define('LOGGED_IN_KEY', 'put your unique phrase here');
52-
define('NONCE_KEY', 'put your unique phrase here');
53-
define('AUTH_SALT', 'put your unique phrase here');
54-
define('SECURE_AUTH_SALT', 'put your unique phrase here');
55-
define('LOGGED_IN_SALT', 'put your unique phrase here');
56-
define('NONCE_SALT', 'put your unique phrase here');
49+
define('AUTH_KEY', $_ENV['AUTH_KEY'] ?? 'put your unique phrase here');
50+
define('SECURE_AUTH_KEY', $_ENV['SECURE_AUTH_KEY'] ?? 'put your unique phrase here');
51+
define('LOGGED_IN_KEY', $_ENV['LOGGED_IN_KEY'] ?? 'put your unique phrase here');
52+
define('NONCE_KEY', $_ENV['NONCE_KEY'] ?? 'put your unique phrase here');
53+
define('AUTH_SALT', $_ENV['AUTH_SALT'] ?? 'put your unique phrase here');
54+
define('SECURE_AUTH_SALT', $_ENV['SECURE_AUTH_SALT'] ?? 'put your unique phrase here');
55+
define('LOGGED_IN_SALT', $_ENV['LOGGED_IN_SALT'] ?? 'put your unique phrase here');
56+
define('NONCE_SALT', $_ENV['NONCE_SALT'] ?? 'put your unique phrase here');
5757

58-
define('WPLANG', '');
58+
define('WPLANG', $_ENV['WPLANG'] ?? '');
5959
if (!defined('ABSPATH')) {
60-
define('ABSPATH', dirname(__FILE__) . '/');
60+
define('ABSPATH', $_ENV['ABSPATH'] ?? dirname(__FILE__) . '/');
6161
}
62-
$table_prefix = 'wp_';
62+
$table_prefix = $_ENV['TABLE_PREFIX'] ?? 'wp_';
6363

6464
require_once(ABSPATH . 'wp-settings.php');

0 commit comments

Comments
 (0)