0

I wanted to see what would be the proper way to call a .env file inside my project? One of the developers that I'm working with, just told me that everything is setup and that all I would need is to create a .env file in the root.

Here is how the function is being called:

$settings = [
    'name' => 'DB_NAME',
    'user' => 'DB_USER',
    'password' => 'DB_PASSWORD',
    'host' => 'DB_HOST',
];

I have my .env file setup as the following (I've created the local database using the below credentials):

cc
cc_user
Z_______0!
localhost

Is this the correct method? Do I need quotes around the name, user, password and host inside the .env file? I am doing all this on a localhost environment.

Mickael B.
  • 4,755
  • 4
  • 24
  • 48
  • 1
    I find the misused `javascript` tag very concerning here. Surely the file you're looking at has a `.php` extension and is more than enough information to tell you what language you're using... – Klaycon Jan 13 '20 at 19:54
  • PHP does not natively load `.env` files, and as such we can only speculate as to what the format is supposed to be. You should ask your coworker. – Sammitch Jan 13 '20 at 20:02

2 Answers2

2

Your .env file should look like this:

DB_NAME=cc
DB_USER=cc_user
DB_PASSWORD=Z_______0!
DB_HOST=localhost

You don't need quotes here

Mickael B.
  • 4,755
  • 4
  • 24
  • 48
1

I suspect you need to set up your .env file with KEY=value pairs, something like


DB_NAME='mydatabase'

Your code sample doesn't give enough to know for sure, but the first thing that comes to mind for me is npm's dotenv package, documentation for which can be found here - https://www.npmjs.com/package/dotenv

dılo sürücü
  • 3,821
  • 1
  • 26
  • 28
Steven
  • 912
  • 1
  • 7
  • 13