Symfony3 does not read the environment variables on Elastic Beanstalk - php

Everything works fine on my local machine. printenv | grep SYMFONY on my local machine prints me this
SYMFONY__DATABASE_HOST=127.0.0.1
SYMFONY__DATABASE_NAME=database
SYMFONY__DATABASE_PASSWORD=root
SYMFONY__DATABASE_PORT=3306
SYMFONY__DATABASE_USER=root
My config.yml contains the following configuration:
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
On my ec2 machine printenv | grep SYMFONY prints the same as above.
But i get the following error message
$ sudo bin/console doctrine:schema:update --force
[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
You have requested a non-existent parameter "database_host".
EDIT: oh and phpinfo(); printes them too. Don't mind the double host and name variables. I tried something.

I made a clean deploy, terminated the ec2 instance and let elastic beanstalk rebuild the ec2 instance.
After that everything worked fine. Maybe i changed some chmods.

Related

Symfony 2.8 - SQL: No such file or directory in "test" environment only

I'm really struggling to get this issue fixed.
I have several Symfony projects I have been working on for months. Since last week, the "test" environment does not work anymore. It just cannot connect to the Mysql DB. This issue is present throughout all Symfony projects. The database config has not been changed and was working perfectly until last week. There is, and always was, a separate DB for the test environment. I did not update any dependencies or something. The weirdest thing is, that all is fine in prod or dev environment.
It really sucks, not being able to run tests locally, so I hope for your expertise!
Thanks in advance and cheers!
config_test.yml:
doctrine:
dbal:
host: localhost
dbname: rims_test
user: root
password:
Solved! alexander-schranz and johannes-wachter from the Sulu.io team provided me with this solution. Thanks a lot!
The solution was to remove a part of the test config:
config_test.yml: BEFORE
doctrine:
dbal:
host: localhost
dbname: rims_test
user: root
password:
config_test.yml: AFTER (Working again!)
doctrine:
dbal:
dbname: rims_test

Create Entity Manager in Symfony3?

I have an existing entity in a Symfony3 project that I am trying to add an entity manager to. My doctrine.yml file looks like this
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
host: localhost
port: 3306
dbname: fullstackdb
user: root
password: root
charset: UTF8
lego:
driver: pdo_mysql
host: localhost
port: 3306
dbname: fullstackdb
user: root
password: root
charset: UTF8
orm:
default_entity_manager: default
entity_managers:
auto_mapping: true
default:
connection: default
mappings:
lego:
connection: lego
mappings:
AppBundle: ~
However anytime I try to access this entity manager through php bin/console doctrine:database:create --connection=lego
, it says the manager does not exist! I'm not sure if I'm missing a step - the only thing I've done to create the manager is to make the yml file.
It doesn't show up when I run bin/console debug:container.
Grateful for any help!
1) You are using the same schema name (database name) on the same host in two different entity managers without schema_filters. This means that when you do an update to one of the entity managers it will attempt to delete the data of the other entity manager.
2) You are asking about a entity manager but in the command you are passing a connection.
3) Run php bin/console debug:container | grep doctrine
This will give you all the doctrine services. Update your question accordingly.
4) Provide the exact command and exact error you get so we can track it down to the origin
5) For a more information run the command in verbose mode adding -v at the end
6) Are you importing your doctrine.yml in your config.yml ?

Connect Doctrine to a MS SQL Database

Just before i get started, I have been trying to figure this out and have clicked nearly every google link there is and I have read nearly all the other questions on this. But I'm stuck because the bundles that are being suggested for this are out of date.
I am creating a website. Tt is a symfony2 application that is being hosted on Microsoft azure. What I want to do is be able to use doctrine of course to fetch and create users to and from the database.
Now from what I've been reading, to connect to this type of database, I have to use the driver called "PDO_dblib".
I have installed this bundle as it seems to be the only one thats still active, don't quote me on that.
https://github.com/realestateconz/MssqlBundle
Now, I installed this in my vendor folder, is this the correct place to store it? Like so:
Project/
app/
src/
vendor/
realestate/
Of course i added the bundle to the AppKernel like so:
new Realestate\MssqlBundle\RealestateMssqlBundle();
and last but not least here is what i have in my config file:
doctrine:
dbal:
default_connection: default
connections:
default:
driver_class: Realestate\MssqlBundle\Driver\PDODblib\Driver
host: %database_host%
dbname: %database_prefix%%database_name%
user: %database_user%
password: %database_password%
so what im thinking im doing here is telling doctrine to use this driver? dont see what else it could be.
I have also declared my parameters.yml for the connection settings.
PS: I am doing my Dev on Linux Mint!
before i tried the steps of this bundle i also ran throught this websites steps: https://dunglas.fr/2014/01/connection-to-a-ms-sql-server-from-symfony-doctrine-on-mac-or-linux/
But again it was throwing errors, I'll post the errors I get down below!
So for the record I have installed freetds and php5-sybase.
The errors that I am getting are such:
[Symfony\Component\Debug\Exception\ContextErrorException]
Warning: class_implements(): Class Realestate\MssqlBundle\Driver\PDODlib\Driver does not exist and could not be loaded
and also this when i try to do a:
php app/console doctrine:database:create
(I do have my entity set up)
but i get the following error from the command of create:
[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
You have requested a non-existent parameter "database_prefix". Did you mean one of these: "database_port", "database_user"?
I have been trying to get this working for the past few days and any help would be fantastic! Any more information needed feel free to ask of course!
According your error code:
[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
You have requested a non-existent parameter "database_prefix". Did you mean one of these: "database_port", "database_user"?
It seems that you miss configuring the parameter “database_prefix”.
If the tables in your database have the unitized prefix e.g. “core_user”,”core_tasks”… You can configure this parameter in the file parameters.yml if not, you can just remove the parameter % database_prefix % in the dbname line in file config.yml.
Here are my code snippets for your reference:
Config.yml:
doctrine:
dbal:
default_connection: default
connections:
default:
driver_class: Realestate\MssqlBundle\Driver\PDODblib\Driver
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
parameters.yml:
parameters:
database_host: {your_sql_server_name}.database.windows.net
database_port: 1433
database_name: {database_name}
database_user: {username}
database_password: {password}
And the test query in controller:
$conn = $this->get('database_connection');
$data = $conn->fetchAll('SELECT * FROM Testtable');
var_dump($data);

Symfony 2 not loading database config file

I'm new to symfony and im following the book with heroku as host, im trying to flush a object to database with doctrine but im getting the following error:
[2015-08-04 05:23:58] request.CRITICAL: Uncaught PHP Exception
PDOException: "SQLSTATE[08006] [7] could not connect to server:
Connection refused Is the server running on host "127.0.0.1" and
accepting TCP/IP connections on port 5432?" at
/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php
line 40 {"exception":"[object] (PDOException(code: 7): SQLSTATE[08006]
[7] could not connect to server: Connection refused\n\tIs the server
running on host \"127.0.0.1\" and accepting\n\tTCP/IP connections on
port 5432? at
/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:40)"}
[]
I got my configuration files working (i guess):
parameters.yml
database_host: host....
database_port: 5432
database_name: ddas1mq8intjqt
database_user: ymmpjzoqbyokbr
database_password: password.....
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
secret: ThisTokenIsNotSoSecretChangeIt
and my config.yml:
doctrine:
dbal:
driver: pdo_pgsql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
I've run the console commands to create the tables from the entity classes and it worked, but creating an object and ->flush seems the problem... don't know if its some server configuration or I've done something wrong.
Thank you
If console command worked, it might be caused by application cache, especially if you run it in prod environment and you have changed database credentials recently. Try to clear the cache for environment you are using (first command for dev, second for prod) and run application again.
php app/console cache:clear
php app/console cache:clear -e prod
I see in error message you used '127.0.0.1', have you tried to type 'localhost' instead? I have similar issue on shared webhosting.

Setup Symfony2 and Postgresql on OS X 10.10 Yosemite?

I can't found a way to setup Symfony with a postgresql database on OS X 10.10 (clean install). Here is what I have done:
1) Install PHP 5.6 from Liip (specially built for Symfony): http://php-osx.liip.ch/
2) Install Postgres.app: http://postgresapp.com/
3) Install Symfony: http://symfony.com/
4) Setup my parameters.yml
parameters:
database_driver: pdo_pgsql
database_host: 127.0.0.1
database_port: 5432
database_name: bachelor
database_user: username
database_password: ~
I have created the DB, verified that I have the right PHP cli, the right pgql cli, etc.
I have created a bundle in Symfony and some entities (no errors here, it works with MySQL).
But when I launch any command to interact with the DB like "php app/console doctrine:schema:update --dump-sql", I have this error:
[PDOException]
SQLSTATE[HY000] [2006] MySQL server has gone away
[Symfony\Component\Debug\Exception\ContextErrorException]
Warning: PDO::__construct(): MySQL server has gone away
But why? I don't use a MySQL server...
Does someone have any solution?
Thanks!
Can you show us your /app/config/config.yml ? please
Did you change the dbal connection value ?
# Doctrine Configuration
doctrine:
dbal:
default_connection: pgsql
connections:
#Postgresql
pgsql:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8

Categories