Setting environment variables¶
This article describes how to set configure environment variables in different environment and even on some common used webservers.
Global configuration of environment variables¶
Shopsys Framework as Symfony based application is using the same environment configuration as Symfony.
We recommend using
.env files for configuring environment variables as it can be easily maintained. There is also advantage of different configuration through different application environments (such as dev, test and prod).
You may also use
.env.local file for your personal configuration. The
*.local files should not be commited so they are ingored with
.gitignore by default.
For better understanding visit the whole documentation here where you can find more info about priority, variables encrypting, syntax and much more.
Overriding by real environment variable of webserver¶
.env files are not enough for your purpose you may override environment variables directly by webserver setting. These settings override any variables configured in
The most common uses are: Kubernetes, Docker or native installation.
Bellow is described the easiest way. For better understanding, we recommend finding out the documentation of the specific platform.
When you are using kubernetes on CI server change your configuration of:
path: ./ingress-patch.yaml + - target: + group: apps + version: v1 + kind: Deployment + name: webserver-php-fpm + path: ./webserver-php-fpm-patch.yaml configMapGenerator: - name: nginx-configuration
+- op: add + path: /spec/template/spec/containers/0/env/- + value: + name: REDIS_PREFIX + value: 'my_awesome_app'
When using docker containers without kubernetes, add the environment variable to the
docker-compose.yml file to
php-fpm definition like in the example below
php-fpm: build: context: . dockerfile: docker/php-fpm/Dockerfile target: development args: www_data_uid: 1000 www_data_gid: 1000 container_name: shopsys-framework-php-fpm volumes: - shopsys-framework-sync:/var/www/html - shopsys-framework-vendor-sync:/var/www/html/vendor - shopsys-framework-web-sync:/var/www/html/web ports: - "35729:35729" + environment: + - REDIS_PREFIX='my_awesome_app'
Without containers you must set environment variable on the host machine, typically in unix like OS by executing