diff --git a/htconfig.php b/htconfig.php index f4ea4d295e..beec41c9c0 100644 --- a/htconfig.php +++ b/htconfig.php @@ -21,6 +21,18 @@ $db_user = 'mysqlusername'; $db_pass = 'mysqlpassword'; $db_data = 'mysqldatabasename'; +// Use environment variables for mysql if they are set beforehand +if (!empty(getenv('MYSQL_HOST')) + && !empty(getenv('MYSQL_PORT')) + && !empty(getenv('MYSQL_USERNAME')) + && !empty(getenv('MYSQL_PASSWORD')) + && !empty(getenv('MYSQL_DATABASE'))) { + $db_host = getenv('MYSQL_HOST') . ':' . getenv('MYSQL_PORT'); + $db_user = getenv('MYSQL_USERNAME'); + $db_pass = getenv('MYSQL_PASSWORD'); + $db_data = getenv('MYSQL_DATABASE'); +} + // Set the database connection charset to full Unicode (utf8mb4). // Changing this value will likely corrupt the special characters. // You have been warned. diff --git a/view/templates/htconfig.tpl b/view/templates/htconfig.tpl index f651a273f7..d72307fb5a 100644 --- a/view/templates/htconfig.tpl +++ b/view/templates/htconfig.tpl @@ -17,6 +17,18 @@ $db_user = '{{$dbuser}}'; $db_pass = '{{$dbpass}}'; $db_data = '{{$dbdata}}'; +// Use environment variables for mysql if they are set beforehand +if (!empty(getenv('MYSQL_HOST')) + && !empty(getenv('MYSQL_PORT')) + && !empty(getenv('MYSQL_USERNAME')) + && !empty(getenv('MYSQL_PASSWORD')) + && !empty(getenv('MYSQL_DATABASE'))) { + $db_host = getenv('MYSQL_HOST') . ':' . getenv('MYSQL_PORT'); + $db_user = getenv('MYSQL_USERNAME'); + $db_pass = getenv('MYSQL_PASSWORD'); + $db_data = getenv('MYSQL_DATABASE'); +} + // Set the database connection charset to full Unicode (utf8mb4). // Changing this value will likely corrupt the special characters. // You have been warned.