Skip to content

Instantly share code, notes, and snippets.

@MushuLeDragon
Last active September 11, 2018 10:02
Show Gist options
  • Save MushuLeDragon/0b5df5dbf57c58b3ecfd3d172ee2c95d to your computer and use it in GitHub Desktop.
Save MushuLeDragon/0b5df5dbf57c58b3ecfd3d172ee2c95d to your computer and use it in GitHub Desktop.

Environment Variable

Set environment variables

Terminal Command Test in Terminal
powershell windows $env:TEST="Bonjour tout le monde" $env:TEST
cmd windows SET TEST=Bonjour tout le monde ECHO %TEST%
shell linux export TEST="Bonjour tout le monde" echo $TEST
Heroku heroku config:set TEST="Bonjour tout le monde" heroku config

Read the environment variable with the development language

Language Command
node const secret = process.env.TEST
PHP $_ENV["TEST"]

Execute PHP file to put your ouwn ENV VARIABLES

In an env.php file :

putenv("HOST=localhost");
putenv("PORT=3306");
putenv("LOGIN=root");
putenv("PWD=");
putenv("DB=my_database");
var_dump(getenv("HOST"), getenv("PORT"), getenv("LOGIN"), getenv("PWD"), getenv("DB"));

To get the variable, use the function getenv(HOST);.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment