SlideShare a Scribd company logo
Environmental
Variables
https://github.com/sketchings/example-env
What are Environments?
Environmental variables
Software Environments
● Local
● Dev
● QA
● Staging
● Production
What are environmental variables?
● Tied to the environment
○ Not tied to a language
○ Not tied to an application
● Used for things that change based on the environment
How can you set them up?
● Apache/Nginx (System wide or Virtual Hosts)
● Hosting Company Dashboard
● Docker
● .htaccess
● Composer Package (.env)
Docker Environment:
DB_SERVER: "db"
DB_NAME: "env-test"
DB_USERNAME: "env"
DB_PASSWORD: "password"
CONFIG_ENV: "development"
S3_BUCKET: "docker bucket"
Using a Package
PHP dotenv
Loads environment variables from .env to getenv(), $_ENV
and $_SERVER automagically.
https://github.com/vlucas/phpdotenv
.env File
DB_SERVER="db"
DB_NAME="env-test"
DB_USERNAME="env"
DB_PASSWORD="password"
CONFIG_ENV="development"
S3_BUCKET="dotenv bucket"
<?php
require __DIR__ . '/vendor/autoload.php';
// can be a relative or absolute path
// optional second parameter for filename, default is .env
$dotenv = DotenvDotenv::createImmutable(__DIR__);
if (getenv('CONFIG_ENV') != "production") {
$dotenv->load();
}
//Immutability refers to if Dotenv is allowed to
overwrite existing environment variables. If you want
Dotenv to overwrite existing environment variables,
use createMutable instead of createImmutable:
$dotenv = DotenvDotenv::createMutable(__DIR__);
Mutability
<?php
require __DIR__ . '/vendor/autoload.php';
$dotenv = DotenvDotenv::createImmutable(__DIR__);
if (getenv('CONFIG_ENV') != "production") {
$dotenv->load();
}
$dotenv->required(
['DB_SERVER', 'DB_NAME', 'DB_USERNAME', 'DB_PASSWORD']
);
What about Security?
● Never check .env files into source control
○ Same applies to sensitive configuration
● Use a secrets manager
○ https://www.phparch.com/magazine/2019/06/how-to-tame-your-data/
Environmental variables
Alena Holligan
● Lead Software Engineer at Lumen Learning
● PHPDX User Group Leader
● Web Developer for 20 years
● Twitter @alenaholligan
File: https://github.com/sketchings/example-env
Slide and to rate this Talk: https://joind.in/talk/cf3cc

More Related Content

PDF
Environmental Variables
PDF
WordCamp Atlanta - April 15 2018 - dev team workflow and processes with word...
PPTX
Grunt and Bower
PDF
What makes me "Grunt"?
PDF
How to Use Mirroring and Caching to Optimize your Container Registry
PDF
Bower & Grunt - A practical workflow
PDF
Case study: JBoss Developer Studio, an IDE for Web, Mobile and Cloud applicat...
PDF
Gradle by Example
Environmental Variables
WordCamp Atlanta - April 15 2018 - dev team workflow and processes with word...
Grunt and Bower
What makes me "Grunt"?
How to Use Mirroring and Caching to Optimize your Container Registry
Bower & Grunt - A practical workflow
Case study: JBoss Developer Studio, an IDE for Web, Mobile and Cloud applicat...
Gradle by Example

What's hot (20)

PDF
Production Ready Javascript With Grunt
PDF
The First 10M Pulls: Building The Official Curl Image for Docker Hub
PDF
Jenkins 2.0 最新事情 〜Make Jenkins Great Again〜
PDF
Mastering Grails 3 Plugins - Greach 2016
PDF
Queue Everything and Please Everyone
PDF
Improving WordPress performance (xdebug and profiling)
PDF
How we maintain 200+ Drupal sites in Georgetown University
PDF
node-webkit : Make a magic from your a desktop app to desktop app!
PDF
Node.js cluster
PPTX
Bower power
PDF
Apache2 BootCamp : Serving Dynamic Content with CGI
PPTX
Vagrant
PPTX
007. Redux middlewares
PDF
wp-cli and plugin development with future and past compatibility (Word Camp P...
PDF
Everything-as-code: DevOps und Continuous Delivery aus Sicht des Entwicklers....
PDF
Docker for the Brave
PDF
Introduction to Express and Grunt
PPTX
Continous Delivery to Kubernetes using Helm
PDF
Everything-as-code – Polyglotte Entwicklung in der Praxis
PDF
Preprocessor Workflow with Grunt
Production Ready Javascript With Grunt
The First 10M Pulls: Building The Official Curl Image for Docker Hub
Jenkins 2.0 最新事情 〜Make Jenkins Great Again〜
Mastering Grails 3 Plugins - Greach 2016
Queue Everything and Please Everyone
Improving WordPress performance (xdebug and profiling)
How we maintain 200+ Drupal sites in Georgetown University
node-webkit : Make a magic from your a desktop app to desktop app!
Node.js cluster
Bower power
Apache2 BootCamp : Serving Dynamic Content with CGI
Vagrant
007. Redux middlewares
wp-cli and plugin development with future and past compatibility (Word Camp P...
Everything-as-code: DevOps und Continuous Delivery aus Sicht des Entwicklers....
Docker for the Brave
Introduction to Express and Grunt
Continous Delivery to Kubernetes using Helm
Everything-as-code – Polyglotte Entwicklung in der Praxis
Preprocessor Workflow with Grunt
Ad

Similar to Environmental variables (20)

KEY
Practical introduction to dev ops with chef
PDF
Declarative Infrastructure Tools
PDF
The Modern Developer Toolbox
PDF
Extending Build to the Client: A Maven User's Guide to Grunt.js
PDF
I Just Want to Run My Code: Waypoint, Nomad, and Other Things
PPTX
Introduction to node.js By Ahmed Assaf
PDF
Practical Chef and Capistrano for Your Rails App
PPTX
WordPress Development Environments
PDF
Developing with-devstack
PDF
From Dev to DevOps - Codemotion ES 2012
PDF
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
PDF
Managing development environments with Docksal
PPTX
Ranger admin dev overview
PDF
LasCon 2014 DevOoops
PDF
Django dev-env-my-way
KEY
From Dev to DevOps - Apache Barcamp Spain 2011
PDF
Improving WordPress Performance with Xdebug and PHP Profiling
KEY
From Dev to DevOps - FOSDEM 2012
PDF
Docker as development environment
PDF
Docker and DevOps --- new IT culture
Practical introduction to dev ops with chef
Declarative Infrastructure Tools
The Modern Developer Toolbox
Extending Build to the Client: A Maven User's Guide to Grunt.js
I Just Want to Run My Code: Waypoint, Nomad, and Other Things
Introduction to node.js By Ahmed Assaf
Practical Chef and Capistrano for Your Rails App
WordPress Development Environments
Developing with-devstack
From Dev to DevOps - Codemotion ES 2012
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Managing development environments with Docksal
Ranger admin dev overview
LasCon 2014 DevOoops
Django dev-env-my-way
From Dev to DevOps - Apache Barcamp Spain 2011
Improving WordPress Performance with Xdebug and PHP Profiling
From Dev to DevOps - FOSDEM 2012
Docker as development environment
Docker and DevOps --- new IT culture
Ad

More from Alena Holligan (20)

PDF
2023 Longhorn PHP - Learn to Succeed .pdf
PDF
Dev parent
PDF
Dependency Injection
PDF
Dependency Management
PDF
Experiential Project Design
PDF
Reduce Reuse Refactor
PDF
Organization Patterns: MVC
PDF
When & Why: Interfaces, abstract classes, traits
PDF
Object Features
PDF
Obect-Oriented Collaboration
PDF
WordCamp Portland 2018: PHP for WordPress
PDF
Let's Talk Scope
PDF
Demystifying Object-Oriented Programming #phpbnl18
PDF
Exploiting the Brain for Fun and Profit
PDF
Learn to succeed
PDF
Demystifying oop
PDF
Demystifying Object-Oriented Programming - PHP[tek] 2017
PDF
Demystifying Object-Oriented Programming - PHP UK Conference 2017
PDF
Exploiting the Brain for Fun & Profit #zendcon2016
PDF
Demystifying Object-Oriented Programming - ZendCon 2016
2023 Longhorn PHP - Learn to Succeed .pdf
Dev parent
Dependency Injection
Dependency Management
Experiential Project Design
Reduce Reuse Refactor
Organization Patterns: MVC
When & Why: Interfaces, abstract classes, traits
Object Features
Obect-Oriented Collaboration
WordCamp Portland 2018: PHP for WordPress
Let's Talk Scope
Demystifying Object-Oriented Programming #phpbnl18
Exploiting the Brain for Fun and Profit
Learn to succeed
Demystifying oop
Demystifying Object-Oriented Programming - PHP[tek] 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017
Exploiting the Brain for Fun & Profit #zendcon2016
Demystifying Object-Oriented Programming - ZendCon 2016

Recently uploaded (20)

PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
Hybrid model detection and classification of lung cancer
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
Tartificialntelligence_presentation.pptx
PDF
Approach and Philosophy of On baking technology
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
TLE Review Electricity (Electricity).pptx
PPTX
Chapter 5: Probability Theory and Statistics
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PPTX
A Presentation on Touch Screen Technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
1 - Historical Antecedents, Social Consideration.pdf
A novel scalable deep ensemble learning framework for big data classification...
Hybrid model detection and classification of lung cancer
NewMind AI Weekly Chronicles - August'25-Week II
Building Integrated photovoltaic BIPV_UPV.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
WOOl fibre morphology and structure.pdf for textiles
Tartificialntelligence_presentation.pptx
Approach and Philosophy of On baking technology
Programs and apps: productivity, graphics, security and other tools
TLE Review Electricity (Electricity).pptx
Chapter 5: Probability Theory and Statistics
Heart disease approach using modified random forest and particle swarm optimi...
A Presentation on Touch Screen Technology
MIND Revenue Release Quarter 2 2025 Press Release
Accuracy of neural networks in brain wave diagnosis of schizophrenia
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation_ Review paper, used for researhc scholars

Environmental variables