Check out the LimeSurvey source code on GitHub!

Using environment variables in LS2 config.php

4 years 6 months ago #83992 by Fred01
I need to use environment variables for database settings in config.php. I've never had any problem with LS prior to v. 2.

In the 1.92 config.php, I use this:
$databaselocation = getenv('MYSQL_DB_HOST'); // Network location of your Database - for odbc_mssql or mssqlnative use the mssql servername, not localhost or IP
$databasename = getenv('MYSQL_DB_NAME'); // The name of the database that we will create
$databaseuser = getenv('MYSQL_USERNAME'); // The name of a user with rights to create db (or if db already exists, then rights within that db)
$databasepass = getenv('MYSQL_PASSWORD'); // Password of db user

The structure of the config file has changed in 2, and I tried the following but it isn't working.

$databaselocation = getenv('MYSQL_DB_HOST');
$databasename = getenv('MYSQL_DB_NAME');
$databaseuser = "'".getenv('MYSQL_USERNAME')."'";
$databasepass = "'".getenv('MYSQL_PASSWORD')."'";
$connectstring = "'mysql:host=".$databaselocation.";dbname=".$databasename."'";


'components' => array(
'db' => array(
'connectionString' => $connectstring,
'emulatePrepare' => true,
'username' => $databaseuser,
'password' => $databasepass,
'charset' => 'utf8',
'tablePrefix' => 'lime_',


Please Log in to join the conversation.

4 years 6 months ago #83993 by Fred01
Nevermind. As I re-read my post I saw the obvious solution. There was no need to wrap single quotes around the values

$databaselocation = getenv('MYSQL_DB_HOST');
$databasename = getenv('MYSQL_DB_NAME');
$databaseuser = getenv('MYSQL_USERNAME');
$databasepass = getenv('MYSQL_PASSWORD');
$connectstring = "mysql:host=".$databaselocation.";dbname=".$databasename;

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form