3

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 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

Hmmm, that was my first attempt and I failed getting this running. Did you really check out, it works? If so, the patch may have been applied already in Symfony source. Thanks anyway, Wolfram

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.