Set values over environment variables in PHP Projects
Imagine you don't want store some sensitiv informations like passwords in your code and you want still keep a part of your configuration in your version control repository.
One approach I describe here is simply using $_ENV
variables.
i.e: $_ENV["APPLICATION_DB_PASSWORD"]
in someproject/application/config/development.rb for yii framework
return array(
'name' => 'LimeSurvey',
'components' => array(
'db' => array(
'connectionString' => 'mysql:host=localhost;port=3306;dbname=myawsomedb',
'emulatePrepare' => true,
'username' => 'someuser',
'password' => $_ENV["APPLICATION_DB_PASSWORD"],
'charset' => 'utf8',
'tablePrefix' => 'xyz_',
))
With .htaccess...
SetEnv APPLICATION_DB_PASSWORD "shpxlbh"
If you are using PHP builtin webserver you just have to set the environment variable in your terminal or add it permanently to your ~/.bashrc
export APPLICATION_DB_PASSWORD="shpxlbh"
Written by Markus Graf
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#