Skip to content

.env example

Pooja Sahu edited this page Dec 14, 2021 · 7 revisions

Environment Variables

Environment variables allow developers to extract sensitive credentials from their source code and to use different configuration variables based on their working environment. Here is an example of a .env file.

# database connection 

DATABASE_HOST = 'ENTER YOUR DATABSE HOST NAME'
DATABASE_USER = 'ENTER YOUR DATABSE USER NAME'
DATABASE_PASS = 'ENTER YOUR DATABSE PASSWORD'
DATABASE_NAME = 'ENTER YOUR DATABSE NAME'


# Set it to 'production' or 'development'
ENVIRONMENT = 'development'

# PATH to minical/public folder (for example, http://localhost/minical/public)
PROJECT_URL = 'http://localhost/minical/public'

# PATH to minical/api folder (for example, http://localhost/minical/api)
API_URL = 'http://localhost/minical/api'

# AWS info

AWS_ACCESS_KEY = 'ENTER YOUR AWS ACCESS KEY HERE'
AWS_SECRET_KEY = 'ENTER YOUR AWS SECRET KEY HERE'
AWS_S3_BUCKET = 'ENTER YOUR AWS S3 BUCKET NAME'


# smtp email info

SMTP_USER = 'ENTER YOUR SMTP USER HERE'
SMTP_PASS = 'ENTER YOUR SMTP PASS HERE'


# Capthcha info

RECAPTCHA_SITE_KEY = 'ENTER YOUR RECAPTCHA SITE KEY HERE'
RECAPTCHA_SECRET_KEY = 'ENTER YOUR RECAPTCHA SECRET KEY HERE'

Usage

All of the defined variables are now available in the $_ENV and $_SERVER super-globals and also in getenv() method.

$aws_access_key = $_ENV['AWS_ACCESS_KEY '];
$aws_secret_key = $_SERVER['AWS_SECRET_KEY '];
$smtp_user= getenv('SMTP_USER');

Keep .env Out of Source Control

Your .env file should be kept out of your version control system. If you are using Git then add the .env file to the .gitignore file so that it will not be committed.