Environment variables for third party tokens and similar, can be accessed for configuration in Neos Flow.
Example: Use in Settings.yaml for database connection
If you have environment variable set, you can use them by setting a value similar to
ENVIRONMENT_VARIABLE_NAME being the name of the key.
For connection to the database it could look like this
Neos: Flow: persistence: backendOptions: dbname: '%env:DATABASE_NAME%' port: '%env:DATABASE_PORT%' user: '%env:DATABASE_USER%' password: '%env:DATABASE_PASSWORD%' host: '%env:DATABASE_HOST%'
Example: Use in configuration of objects with Objects.yaml
Objects.yaml in Neos Flow, you can set values of contsructor arguments and properties. In this file, you can also pass environment variables by using the
In this example I set two constructor argument, with values that is environment independent, and can be changed on the environment, without changing code or duplicating the implementation
Vendor\Application\Consumer\Provider: arguments: 1: value: '%env:CONSUMER_API_CLIENT_ID%' 2: value: '%env:CONSUMER_API_CLIENT_SECRET%'
Use .env file in your local development environment
The PHP package
helhum/dotenv-connector makes it simply for you to use a
.env file with similar values of, what you are setting in your hosting environment.
As an example I have a
.env file like this
And simply because I’ve installed
helhum/dotenv-connector I can now use the
Settings.yaml file shown above, to configure the database connection.
At the same time, my staging and production environments has the same variables and therefore, the configuration file is a part of the repository and no code changes required