user12160926
user12160926

Reputation:

Proper way to call .env file inside project

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.

Upvotes: 0

Views: 1698

Answers (2)

Steven
Steven

Reputation: 927

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

Upvotes: 1

Mickael B.
Mickael B.

Reputation: 5205

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

Upvotes: 2

Related Questions