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.
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.
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.
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.
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.
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With