T
T
Tamara Lamova2021-08-25 22:32:48
PHP
Tamara Lamova, 2021-08-25 22:32:48

How do the variables from the .env file for Docker get into $_ENV?

There is a PHP project in the form of a git repository.

It is proposed to deploy it through docker.
There are default settings in the docker configs, the project opens on localhost.
The config.php in the project uses data from $_ENV, which, when run through docker, magically turns out to be filled with the necessary data from the .env file.

Only one snag.
Configs are not allowed to be changed.
But it's uncomfortable for me.
I have Linux on my machine (lamp and that's all) and deploying the same project without using docker, with my own host name , is a little easier and faster and more convenient for me personally for development. And my localhost is busy with something else.

I do not have the right to add any of the "Dot Env" type libraries to the project to process the .env file.
And there is no such thing in the project.

So how can I make sure that without running the project through docker, my $_ENV is magically filled with data from the .env file (without adding additional libraries and files to the project to process .env )?
How does it happen in a container?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
vilinyh, 2021-08-26
@tom-lam

6126b2355f602704310291.png

P
profesor08, 2021-08-25
@profesor08

It is written what it is and where it comes from
https://www.php.net/manual/ru/reserved.variables.e...

N
nokimaro, 2021-08-25
@nokimaro

Tamara Lamova Tamara Lamova Asker Just
added to /etc/apache2/envvars , restarted Apache.
It worked.

apache - SetEnv
httpd.apache.org/docs/current/mod/mod_env.html#setenv
for example put in .htaccess
SetEnv SPECIAL_PATH /example/test
SetEnv APPLICATION_ENV production

nginx - fastcgi_param
https://nginx.org/ru/docs/http/ngx_http_fastcgi_mo...
location / {
...
   fastcgi_param   APPLICATION_ENV  production;
   fastcgi_param   SPECIAL_PATH  /example/test;
...
}

cli
https://linuxize.com/post/how-to-set-and-list-envi...
env APP_NAME=MyAPP php -r 'var_dump(getenv("APP_NAME"));'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question