With Symfony 5.2, when I execute this command
APP_ENV=prod php bin/console d:m:m
I have this message :
WARNING! You are about to execute a migration in database "db_name" that could ...
However, in my Apache environment variables, I customized the database name :
SetEnv DATABASE_URL "mysql://website:password@localhost:3306/website_prod"
I am sure that this configuration works (when I access the site, I am in the prod
environment while I left dev
in the .env
generated by Symfony).
Why is the wrong database displayed on the APP_ENV=prod php bin/console d:m:m
command line? I think Apache variables are not taken into account in php bin / console ...
command line and I need to create a specific .env.prod.local
.
Can you confirme ? If yes, I don't see why Symfony mentions this in their documentation (https://symfony.com/doc/current/setup/web_server_configuration.html#apache-with-mod-php-php-cgi)
Console commands do not run under the web-server, hence they do not have access to whatever configuration you have for the Apache vhost or anything like that.
The best way to deal with this kind of configuration is storing this values in environment variable, .env
files, or use Symfony's secret management features.
This way this configuration will be available both to the application when accessed via the webserver or through a command line script.