Define Environment Variables

Page last updated:

Page last updated:

Cloud Foundry lets you externalize configuration - storing data such as encryption keys or external resource addresses in environment variables.

At runtime, environment variables are exposed to the application through its environment. You can use these to configure different parameters of your app or to change the mode your app runs in. Here’s an example:

$ cf set-env my-php-app APP_MODE production
Setting env variable 'APP_MODE' to 'production' for app my-php-app in org MyOrg / space MySpace as user@smydomain.com...
OK
TIP: Use 'cf restage' to ensure your env variable changes take effect

Then restage your app as suggested using

$ cf restage my-php-app
Restaging app my-php-app in org MyOrg / space MySpace as user@mydomain.com...
-----> Downloaded app package (8.0K)
-----> Downloaded app buildpack cache (2.3M)

...

All environment variables are accessed using $_ENV['ENV_VARIABLE'] or the Lumen specific style with env('ENV_VARIABLE').

I’ve set my environment variable
View the source for this page in GitHub