0

I work on an application where our database administrator has mandated that the production database credentials be inaccessible to anyone that's not a database admin or the web app itself. He suggested we create a second .env file that contains only the database credentials so that he can lock down that file. Is there a way to do this? Essentially we would be reading config values from both .env files.

For example our app config file might look like

return [
    'some_configuration' => env1('SOME_CONFIGURATION'),
]

While the database config file might look like

return [
    'database_password' => env2('DB_PASSWORD')
]

How can I read configs from multiple .env files like this?

4
  • Do you not just have a local database for development? Commented Jun 14, 2017 at 15:15
  • 1
    It was removed in Laravel 5. You can access similar behavior with an external package, like github.com/phanan/cascading-config. Alternatively, you can roll your own with something like parse_ini_file and array_merge. Commented Jun 14, 2017 at 15:15
  • 3
    You could grab the password from an arbitrary file via file_get_contents, i.e. 'database_password' => file_get_contents('.secret_file'), but I'm dubious of the value here. If it's available to the web app, it's available to a developer via php artisan tinker or just dumping it out in a secret route or something. Commented Jun 14, 2017 at 15:16
  • @ceejayoz The arbitrary file looks like the way I have to go. And yes it can probably be circumvented but from my understanding it's less to protect it from the actual developers, but rather provide protection in the case of a unattended terminal or a theft of a developers server access credentials. If you post your comment as an answer I can mark it as correct since it resolves my issue. Commented Jun 14, 2017 at 17:04

1 Answer 1

1

Your best bet will probably be using an arbitrary file and getting its contents via file_get_contents:

return [
    'database_password' => trim(file_get_contents('.secret_file'))
]

(The trim is in case your database administrator leaves a stray \n or space or something.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.