3
votes

I am developing an new Symfony 4.0 app in a docker container (Apache SSL container is proxying to Symfony container). All fine for dev environment. Within docker container APP_ENV is set to prod (cross checked by entering running docker container and issuing SET command). I removed symfony/dotenv from composer... all well with no errors.

But calling my site it still tells me APP_ENV is not defined. What am I missing?

I read here about duplicating APP_ENV into "/etc/environment". I did not see it in Symfony docs yet. Any hint to this source?

Thanks, Wolfram

2

2 Answers

1
votes

I'd like to share the answer that I have found: In Docker environment $_ENV var is used to retrieve environment variables. The Symfony team has implemented retrievel of environment variables in $SERVER.

Documented here: https://github.com/symfony/recipes/issues/331

A patch within index.php (provided in the link above) will temporarily solve this problem.

Wolfram

0
votes

I was having the same issue, however on Symfony's documentation regarding putting symfony in production mode with Apache, they provide this:

ServerName domain.tld ServerAlias www.domain.tld

DocumentRoot /var/www/project/public
<Directory /var/www/project/public>
    AllowOverride None
    Order Allow,Deny
    Allow from All

    <IfModule mod_rewrite.c>
        Options -MultiViews
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ index.php [QSA,L]
    </IfModule>
</Directory>

# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeeScript assets
# <Directory /var/www/project>
#     Options FollowSymlinks
# </Directory>

# optionally disable the RewriteEngine for the asset directories
# which will allow apache to simply reply with a 404 when files are
# not found instead of passing the request into the full symfony stack
<Directory /var/www/project/public/bundles>
    <IfModule mod_rewrite.c>
        RewriteEngine Off
    </IfModule>
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined

# optionally set the value of the environment variables used in the application
#SetEnv APP_ENV prod
#SetEnv APP_SECRET <app-secret-id>
#SetEnv DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name"

Notice this part (just above):

# optionally set the value of the environment variables used in the application
#SetEnv APP_ENV prod
#SetEnv APP_SECRET <app-secret-id>
#SetEnv DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name"

Setting your environment variables here, will work (with docker) and no hacks required for Symfony's index.php.