Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Heroku config vars with PHP?

Tags:

php

heroku

I've been able to find information on how to use config vars in Heroku for Python, node.js, and some other languages, but not for PHP. Can you use them with PHP, or is it not supported?

This article shows how to do it for Python, Java, and Ruby, but not PHP.

like image 972
mp94 Avatar asked Feb 06 '14 02:02

mp94


People also ask

Does Heroku work with PHP?

Heroku recognizes an app as PHP by the existence of a composer. json file in the root directory. The composer. json file specifies the dependencies that should be installed with your application.

Does .env work in Heroku?

env file is not enough. You need to set the environment variables for your application on Heroku. There are two ways to do it, and in this article, you can see both! The environment variables are called config variables (config vars) on Heroku.

How do I access Heroku config vars in react?

If you use Create React App (or react-scripts), prepend the variable with REACT_APP_ , for instance, REACT_APP_BASE_URL , and Create React App automatically uses its value during the build process, making it then accessible in the process. env.

Are Heroku config vars safe?

Heroku config vars are designed to be safe for storing sensitive information. All config vars are stored in an encrypted form and safely stored. These are only decrypted and loaded when booting your app in a dyno itself.


1 Answers

Config vars on heroku manifest themselves as environment variables, so you should be able to access them from php like you would any other environment variable, eg. using getenv.

First, set the variable from your console:

heroku config:set MY_VAR=somevalue

Then, access it from your code:

$my_env_var = getenv('MY_VAR');
like image 153
Moritz Avatar answered Oct 26 '22 03:10

Moritz