1

Currently working on the deployment of a Magento 2.2.x instance and I can't seem to find any documentation regarding the ability to set the database connection parameters as environmental variables.

I have looked at the documentation on how to Use environment variables to override configuration settings but can't seem to find anything related to this.

Anyone knows if this is possible with a default Magento 2.2.x instance? If so, what are the environmental variables keys that I can use?

Thanks!

Edit: Found a way of doing this thanks to the accepted answer below. Part of app/etc/env.php:

...
array (
    'host' => !empty($_SERVER['CONFIG_DB_HOST']) ? $_SERVER['CONFIG_DB_HOST'] : '',
    'dbname' => !empty($_SERVER['CONFIG_DB_DBNAME']) ? $_SERVER['CONFIG_DB_DBNAME'] : '',
    'username' => !empty($_SERVER['CONFIG_DB_USERNAME']) ? $_SERVER['CONFIG_DB_USERNAME'] : '',
    'password' => !empty($_SERVER['CONFIG_DB_PASSWORD']) ? $_SERVER['CONFIG_DB_PASSWORD'] : '',
    'active' => '1',
  ),
...

1 Answer 1

0

If you are using Apache, you can set a $_SERVER variable in the vhost config:

SetEnv name "value"

This new variable will appear in $_SERVER, not $_ENV. You can access it from Magento's env.php by $_SERVER['name']. You can also define $_ENV variables from index.php:

$_ENV['name'] = 'value';

There's no pre defined name for database configuration, so you will need to edit app/etc/env.php

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.