Commit 928b4b02 authored by Fabio Montefuscolo's avatar Fabio Montefuscolo

let user override all wp-config configuration

parent 38a8af5b
......@@ -24,9 +24,11 @@ COPY wp-config.php /var/www/html/wp-config.php
RUN chown -R www-data: /var/www/html/ \
&& mkdir -p /docker-entrypoint-extra \
&& mkdir -p /var/www/html/wp-config.d \
&& echo "alias wp='/usr/local/bin/wp --allow-root'" >> /root/.bashrc
ENV PAGER /bin/cat
VOLUME ["/var/www/html/wp-config.d"]
EXPOSE 80 443
ENTRYPOINT ["/entrypoint.sh"]
......
......@@ -5,6 +5,47 @@ can be used to host a WordPress site as well. There are some tools
and nice librarys included, like *OPCache*, *X-Debug* and *WP-Cli*.
## Overriding configurations
You can override wp-config.php values by using environment variables. Actually, the variables present on wp-config.php and values when variable is not defined are below.
| Variable Name | Default Value |
|----------------------------|-----------------------------------|
| HTTPS | |
| WORDPRESS_AUTH_KEY | `<random string>` |
| WORDPRESS_AUTH_SALT | `<random string>` |
| WORDPRESS_LOGGED_IN_KEY | `<random string>` |
| WORDPRESS_LOGGED_IN_SALT | `<random string>` |
| WORDPRESS_NONCE_SALT | `<random string>` |
| WORDPRESS_SECURE_AUTH_KEY | `<random string>` |
| WORDPRESS_SECURE_AUTH_SALT | `<random string>` |
| WORDPRESS_NONCE_KEY | `<random string>` |
| WORDPRESS_DB_CHARSET | utf8 |
| WORDPRESS_DB_COLLATE | |
| WORDPRESS_DB_HOST | mysql |
| WORDPRESS_DB_NAME | wordpress |
| WORDPRESS_DB_PASSWORD | wordpress |
| WORDPRESS_DB_USER | wordpress |
| WORDPRESS_DEBUG | false |
| WORDPRESS_DEBUG_DISPLAY | false |
| WORDPRESS_DEBUG_LOG | false |
| WORDPRESS_FS_METHOD | direct |
| WORDPRESS_TABLE_PREFIX | wp_ |
| WORDPRESS_HOME | `<?= $_SERVER['SERVER_NAME']; ?>` |
| WORDPRESS_SITEURL | `<?= $_SERVER['SERVER_NAME']; ?>` |
## Overriding variables not defined on wp-config.php
If you have variables not present on table above, you can mount a folder with your configuration at `/var/www/html/wp-config.d`. All php files on that directory will be included on `wp-config.php`. You can also override variables present on default `wp-config.php`.
### Parental advisory
If you are running behind a reverse proxy and inside a Virtual Host, you may be safe about `WORDPRESS_HOME` and `WORDPRESS_SITEURL` default values.
But if you container receive requests with unexpected `SERVER_NAME`, you __must__ provide values for those variables.
In any case, it is a good idea to provide values for those variables.
## Development environment
There are a WordPress installed at `/var/www/html`. So if you want
......
<?php
define('DB_USER', getenv('WORDPRESS_DB_USER') ?: 'wordpress');
define('DB_NAME', getenv('WORDPRESS_DB_NAME') ?: 'wordpress');
define('DB_PASSWORD', getenv('WORDPRESS_DB_PASSWORD') ?: 'wordpress');
define('DB_HOST', getenv('WORDPRESS_DB_HOST') ?: 'mysql');
define('DB_CHARSET', getenv('WORDPRESS_DB_CHARSET') ?: 'utf8');
define('DB_COLLATE', getenv('WORDPRESS_DB_COLLATE') ?: '');
define('AUTH_KEY', getenv('WORDPRESS_AUTH_KEY'));
define('SECURE_AUTH_KEY', getenv('WORDPRESS_SECURE_AUTH_KEY'));
define('LOGGED_IN_KEY', getenv('WORDPRESS_LOGGED_IN_KEY'));
define('NONCE_KEY', getenv('WORDPRESS_NONCE_KEY'));
define('AUTH_SALT', getenv('WORDPRESS_AUTH_SALT'));
define('SECURE_AUTH_SALT', getenv('WORDPRESS_SECURE_AUTH_SALT'));
define('LOGGED_IN_SALT', getenv('WORDPRESS_LOGGED_IN_SALT'));
define('NONCE_SALT', getenv('WORDPRESS_NONCE_SALT'));
define('FS_METHOD', getenv('WORDPRESS_FS_METHOD') ?: 'direct');
$table_prefix = getenv('WORDPRESS_TABLE_PREFIX') ?: 'wp_';
define('WP_DEBUG', getenv('WORDPRESS_DEBUG') === 'true');
define('WP_DEBUG_LOG', getenv('WORDPRESS_DEBUG_LOG') === 'true');
define('WP_DEBUG_DISPLAY', getenv('WORDPRESS_DEBUG_DISPLAY') === 'true');
foreach(glob(dirname(__FILE__) . '/' . 'wp-config.d/*.php') as $config) {
include($config);
}
!defined('DB_USER') && define('DB_USER', getenv('WORDPRESS_DB_USER') ?: 'wordpress');
!defined('DB_NAME') && define('DB_NAME', getenv('WORDPRESS_DB_NAME') ?: 'wordpress');
!defined('DB_PASSWORD') && define('DB_PASSWORD', getenv('WORDPRESS_DB_PASSWORD') ?: 'wordpress');
!defined('DB_HOST') && define('DB_HOST', getenv('WORDPRESS_DB_HOST') ?: 'mysql');
!defined('DB_CHARSET') && define('DB_CHARSET', getenv('WORDPRESS_DB_CHARSET') ?: 'utf8');
!defined('DB_COLLATE') && define('DB_COLLATE', getenv('WORDPRESS_DB_COLLATE') ?: '');
!defined('AUTH_KEY') && define('AUTH_KEY', getenv('WORDPRESS_AUTH_KEY'));
!defined('SECURE_AUTH_KEY') && define('SECURE_AUTH_KEY', getenv('WORDPRESS_SECURE_AUTH_KEY'));
!defined('LOGGED_IN_KEY') && define('LOGGED_IN_KEY', getenv('WORDPRESS_LOGGED_IN_KEY'));
!defined('NONCE_KEY') && define('NONCE_KEY', getenv('WORDPRESS_NONCE_KEY'));
!defined('AUTH_SALT') && define('AUTH_SALT', getenv('WORDPRESS_AUTH_SALT'));
!defined('SECURE_AUTH_SALT') && define('SECURE_AUTH_SALT', getenv('WORDPRESS_SECURE_AUTH_SALT'));
!defined('LOGGED_IN_SALT') && define('LOGGED_IN_SALT', getenv('WORDPRESS_LOGGED_IN_SALT'));
!defined('NONCE_SALT') && define('NONCE_SALT', getenv('WORDPRESS_NONCE_SALT'));
!defined('FS_METHOD') && define('FS_METHOD', getenv('WORDPRESS_FS_METHOD') ?: 'direct');
!defined('WP_DEBUG') && define('WP_DEBUG', getenv('WORDPRESS_DEBUG') === 'true');
!defined('WP_DEBUG_LOG') && define('WP_DEBUG_LOG', getenv('WORDPRESS_DEBUG_LOG') === 'true');
!defined('WP_DEBUG_DISPLAY') && define('WP_DEBUG_DISPLAY', getenv('WORDPRESS_DEBUG_DISPLAY') === 'true');
if(!isset($table_prefix)) {
$table_prefix = getenv('WORDPRESS_TABLE_PREFIX') ?: 'wp_';
}
if ( !WP_DEBUG_LOG ) {
ini_set('log_errors', 1);
ini_set('error_log', 'php://stderr');
}
if ( !defined('ABSPATH') ) {
define('ABSPATH', dirname(__FILE__) . '/');
}
if(getenv('HTTPS') === 'on') {
$_SERVER['HTTPS'] = 'on';
}
......@@ -40,9 +42,29 @@
$_SERVER['HTTPS'] = 'on';
}
foreach(glob(ABSPATH . 'wp-config.d/*.php') as $config) {
include($config);
$proto = 'http://';
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
$proto = 'https://';
}
require_once(ABSPATH . 'wp-settings.php');
if(!defined('WP_HOME')) {
if (getenv('WORDPRESS_HOME')) {
define('WP_HOME', getenv('WORDPRESS_HOME'));
} else {
define('WP_HOME', $proto . $_SERVER['SERVER_NAME']);
}
}
if(!defined('WP_SITEURL')) {
if (getenv('WORDPRESS_SITEURL')) {
define('WP_SITEURL', getenv('WORDPRESS_SITEURL'));
} else {
define('WP_SITEURL', $proto . $_SERVER['SERVER_NAME']);
}
}
unset($proto);
if (!defined('ABSPATH') ) {
define('ABSPATH', dirname(__FILE__) . '/');
}
require_once(ABSPATH . 'wp-settings.php');
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment