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.
Related
I use Symfony 3.1.5 and I am trying to run a simple
php bin/console doctrine:database:create
as it is described in the documentation.
My parameters.yml
parameters:
database_host: hhvm_db_1
database_port: 5432
database_name: dbname
database_user: dbuser
database_password: mypassword
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 get the following error messages:
[Doctrine\DBAL\Exception\DriverException]
An exception occured in driver: [32681]: could not translate host name "hhvm_db_1
port=5432 dbname=postgres " to address: Name or service not known
[Doctrine\DBAL\Driver\PDOException]
[32681]: could not translate host name "hhvm_db_1 port=5432 dbname=postgres " to a
ddress: Name or service not known
[PDOException]
[32681]: could not translate host name "hhvm_db_1 port=5432 dbname=postgres " to a
ddress: Name or service not known
The error message looks odd to me, because it states dbname=postgres while I have a different database specified in my parameters.yml. I tried to change it directly in the config.yml, but that does not change a thing. Database host and port are taken from my parameters.yml though.
I suppose doctrine is just using default parameters for dbname, as it cannot parse my parameters for some reason. What could be the problem here?
I don't think this is really the issue, but I am running symfony in a docker container with hhvm. hhvm_db_1 in the above error message is the second container running Postgres. When I check the connection with vanilla PHP it works and I can connect to the database. Thus, the host is accessible from my web container.
I found that my system is having problems with the dsn string containing spaces instead of semicolons.
Does not work:
pgsql:host=hhvm_db_1 port=5432 dbname=postgres
Works fine:
pgsql:host=hhvm_db_1;port=5432;dbname=postgres
My initial problem was also solved by that. The DBAL driver for PDOPgSQL is using postgres as the default database to check the connection.
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.
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
I cannot succeed in creating a database with Symfony throught the terminal
(I use a MAC and MAMP)
The line in the Terminal
MacBook-Pro-de-XXX:Symfony XXX$ php app/console doctrine:database:create
The answer I got in Terminal
Warning: PDO::__construct(): MySQL server has gone away in /Applications/MAMP/htdocs/Symfony/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php on line 40
Warning: PDO::__construct(): Error while reading greeting packet. PID=52773 in /Applications/MAMP/htdocs/Symfony/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php on line 40
Could not create database for connection named `symfony`
SQLSTATE[HY000] [2006] MySQL server has gone away
Here some other information that might help you help me to find where the probleme come from
the parameters.yml file in Symfony/app/config
# This file is auto-generated during the composer install
parameters:
database_driver: pdo_mysql
database_host: localhost:8888
database_port: null
database_name: symfony
database_user: root
database_password: root
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
locale: en
secret: ThisTokenIsNotSoSecretChangeIt
modify your host. if you have running mySql service on port 8888 your configuration should be as
database_host: localhost
database_port: 8888
if your mysql running on default port, use below configuration
database_host: localhost
database_port: null
hope this helps.
sorry for my bad english.
Make sure that the MySQL server is actually running. Also the MAMP default port for MySQL is 3306 and not 8888.
database_host: localhost
database_port: 3306
I'm following the Symfony book and arrived at the chapter on dealing with the database. I have a few questions, and can't seem to find an answer.
I'm just following the parameters.yml file that I have looks like this (auto-generated)
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: null
database_name: myproject
database_user: root
database_password: null
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
locale: en
secret: ThisTokenIsNotSoSecretChangeIt
debug_toolbar: true
debug_redirects: false
use_assetic_controller: true
Then I head over to the terminal and enter:
php app/console doctrine:database:create
I receive the following error:
Could not create database for connection named `myproject`
SQLSTATE[HY000] [2002] Connection refused
I have a few questions:
How do I fix this
Where is the database server? Did it come when I installed Symfony2 with Composer?
After a long search I found it. It had something to do with the mysql.default_socket as pointed out in the comments.
MAMP showed me the socket was
':/Applications/MAMP/tmp/mysql/mysql.sock'
After doing some more searching, I found that the socket can be set in config.yml, here:
doctrine:
dbal:
driver: "%database_driver%"
[...]
unix_socket: "/Applications/MAMP/tmp/mysql/mysql.sock"
[...]
If the unix_socket line is not there, just add it. Then tried to execute the same command in Terminal, which gave this result:
Created database for connection named `myproject`
And the database was really created.
Symfony doesn't install mysql I assume you are working in a lamp stack.
If I remember well it happened to me once and I changed database_host: 127.0.0.1 to localhost and it worked well since.