How to version control config files pragmatically?

后端 未结 9 1144
日久生厌
日久生厌 2020-11-30 02:04

Suppose we have a config file with sensitive passwords. I\'d like to version control the whole project, including the config file as well, but I don\'t want to share my pass

9条回答
  •  孤城傲影
    2020-11-30 02:24

    Create a local overrides file that contains the user specific info as PHP variables.

    For instance create a file called local_overrides.php which contains the following:

    $local_password = 'qUzaEAFK13uK2KHy';
    

    Then in the file that includes your DB password do something like this

    $overrides = 'local_overrides.php';
    
    if (file_exists($overrides)) {
       #include_once($overrides);
       $db_password = $local_password;
    } else {
       // perform appropriate action: set default? echo error message? log error?    
       $db_password = 'l1m1t3d!'
    }
    

    The local overrides file would never has to be seen by source control.

提交回复
热议问题