Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1.  
  2. example inside FOO_VAR.env
  3. located somewhere in your secret folder
  4.  
  5. PROD_DB_USERNAME = "foobar"
  6. PROD_DB_PASSWORD = "veryveryharduncrackablepassword"
  7. PROD_DB_HOST = "localhost"
  8. PROD_DSN = "mysql:host=localhost;dbname=something_db"
  9.  
  10. then in your web/index.php
  11.  
  12. <?php
  13. // comment out the following two lines when deployed to production
  14. defined('YII_DEBUG') or define('YII_DEBUG', true);
  15. defined('YII_ENV') or define('YII_ENV', 'dev');
  16. require(__DIR__ . '/../vendor/autoload.php');
  17. require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
  18. # load the environment before loading the configuration
  19. (new Dotenv\Dotenv(dirname(__FILE__) . '/../' , 'APP_DEV.env' ))->load();
  20. $config = require(__DIR__ . '/../config/web.php');
  21. (new yii\web\Application($config))->run();
  22.  
  23. then inside your config/db.php
  24.  
  25. $dbConf = [
  26. 'class' => 'yii\db\Connection',
  27. 'dsn' => getenv('PROD_DSN'),
  28. 'username' => getenv('PROD_DB_USERNAME'),
  29. 'password' => getenv('PROD_DB_PASSWORD'),
  30. 'charset' => 'utf8',
  31. ];
  32. return $dbConf;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement