Reputation: 2683
Running a single nginx instance on a V-Server I want to have two separate Symfony installations:
The first installation is running a few month now, the second was installed recently and is publicly accessible, BUT it uses the database connection of the first one when handling it via console!
...
location ~ ^/index\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param APP_ENV prod;
fastcgi_param APP_SECRET XXX;
fastcgi_param DATABASE_URL "mysql://user:[email protected]:3306/symfony1_db";
...
}
...
...
location ~ ^/index\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param APP_ENV prod;
fastcgi_param APP_SECRET XXX;
fastcgi_param DATABASE_URL "mysql://user:[email protected]:3306/symfony2_db";
...
}
...
When I try to create the schema for the second installation (php /var/www/html/smyfony2/bin/console doctrine:database:create
, it gives me this error:
Could not create database
symfony1_db
for connection named default
My idea was to change the
fastcgi_param DATABASE_URL "mysql://user:[email protected]:3306/symfony2_db";
to
fastcgi_param DATABASE_URL_2 "mysql://user:[email protected]:3306/symfony2_db";
but
is that necessary?
is that even possible?
where would I have to tell that to my Symfony installation
Any hint is highly appreciated.
Everything works fine when I access the site via browser, it's just confusing sth in my console.
Upvotes: 0
Views: 64
Reputation: 52523
Your nginx configuration is not applied if you invoke the console
command in your terminal and therefore has nothing to do with your problem.
You can solve this problem by adding the symfony/dotenv
package to your application.
composer require symfony/dotenv
Then enable the component inside your bin/console
file:
(new Dotenv())->load(__DIR__.'/../.env');
Now create two .env
files with the correct database parameters/environment-variables in the root folder of both of your applications.
# .env
DATABASE_URL='mysql://user:[email protected]:3306/symfony2_db'
Further you could use tool like direnv to load different environment variables environment dependening on your shell's current working directory.
Upvotes: 1