Welcome, Guest
Username: Password: Remember me

TOPIC: Using environment variables in LS2 config.php

Using environment variables in LS2 config.php 2 years 1 month ago #83992

  • Fred
  • Fred's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 163
  • Thank you received: 5
  • Karma: 3
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_',
),

etc...
The administrator has disabled public write access.

Re: Using environment variables in LS2 config.php 2 years 1 month ago #83993

  • Fred
  • Fred's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 163
  • Thank you received: 5
  • Karma: 3
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;
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.094 seconds
Donation Image