In Symfony 4, the index.php sets dev mode by default
$env = $_SERVER['APP_ENV'] ?? 'dev';
Symfony official doc says : Symfony Dotenv should only be used in development/testing/staging environments. For production environments, use "real" environment variables.
So I understand : APP_ENV=prod
as environment variable is mandatory to enable prod mode.
Am I right?
You have to ensure that the environment variable APP_ENV
is set correctly in your production environment. The documentation tells you how to do this for various web servers. For example, in your Apache-configuration you have to use SetEnv
. This could look something like this:
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>
SetEnv APP_ENV prod
SetEnv APP_DEBUG 0
...
A similar configuration for nginx would use fastcgi_param
and would look somewhat like this:
location ~ ^/index\.php(/|$) {
fastcgi_pass unix:/var/run/php7.1-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param APP_ENV prod;
fastcgi_param APP_DEBUG 0;
}
The doc page is a bit mean, because the respective bits are commented out.
If you want to simulate the production environment with the built-in webserver you can do it like this:
APP_ENV=prod APP_DEBUG=0 bin/console server:run
This requires the server-pack to be installed using composer and of course you can also set the command option --env
as well, for the same effect.
And also make sure that you have checked .env
and .env.local
file too.
# prod config of .env or/and .env.local
APP_ENV=prod
APP_DEBUG=0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With