phpenvironment-variablesphpdotenv

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.


Solution

  • 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