In localhost, symfony console doctrine:database:create
runs perfectly.
But when I try to install the project for production on Ubunthu server, that does not work.
I have a .env file with vars like :
.env
###> symfony/framework-bundle ###
APP_ENV=%APP_ENV%
APP_SECRET=%APP_SECRET%
###< symfony/framework-bundle ###
###> doctrine/doctrine-bundle ###
DATABASE_URL="mysql://%DB_USER%:%DB_PASS%@%DB_SERVER%/%DB_DBNAME%?serverVersion=%DB_VERSION%&charset=utf8mb4"
###< doctrine/doctrine-bundle ###
###> nelmio/cors-bundle ###
CORS_ALLOW_ORIGIN='%CORS_ALLOW_ORIGIN%'
###< nelmio/cors-bundle ###
and
.env.prod
APP_ENV=prod
APP_SECRET=xxxxxxx
CORS_ALLOW_ORIGIN=^https?://(admin.|)(example.com)(:[0-9]+)?$
DB_USER=xxxxx
DB_PASS=xxxx
DB_SERVER=xxxxx:3306
DB_DBNAME=mydbname
DB_VERSION=10.11.2-MariaDB
I´m trying to run symfony console doctrine:database:create
but by ssh that does not work and I got this error :
[critical] Error thrown while running command "doctrine:database:create". Message: "Malformed parameter "url"."
In ConnectionFactory.php line 262:
Malformed parameter "url".
In MalformedDsnException.php line 12:
Malformed database connection URL
doctrine:database:create [-c|–connection [CONNECTION]] [–if-not-exists]
even if I try to set each var before like…
export DB_USER=foo
So what is the best way to deploy on production
… run easily
symfony console doctrine:database:create
symfony console doctrine:schema:create
.. and Symfony/doctrine can interprates .env with vars without I need to gitignore doctrine.yaml
and .env
?
2
Answers
Actually there were different matters to create Symfony database during production deployment we need by SSH :
?
or other special character swhich can be encoded in the database user password. I could tested this withcomposer dump-env prod
and discover this kind of error.sudo mysql -u root
SHOW GRANTS FOR 'username'@'%';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%';
FLUSH PRIVILEGES;
I think symfony loads
.env.prod
only ifAPP_ENV
already set to prod in.env
or.env.local
.Create
.env.local
on production machine and putAPP_ENV=prod
there.Or just put
APP_ENV=prod
into.env
, but in this case you will need to setAPP_ENV=dev
into.env.local
on development machine.