I'm deploying my symfony2 project and I'm having problems with the database connection to a remote mysql server. It seems like symfony was still trying to connect to a local mysql instance (using socket instead of tcp) and not taking into account the parameteres.yml where are the correct settings.
parameters.yml
parameters:
database_driver: pdo_mysql
database_host: subdomain-example.dotcloud.net
database_port: 44569
database_name: db_platform
database_user: root
database_password: [intentionally hidden]
config.yml
imports:
- { resource: parameters.yml }
doctrine:
dbal:
default_connection: default
connections:
default:
driver: %database_driver%
dbname: %database_name%
user: %database_user%
password: %database_password%
host: %database_host%
port: %database_port%
charset: UTF8
Error stack trace (shown by the console when I try to clear cache or by the http browser)
PDOException: SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: YES)
in /var/www/Symfony/app/cache/dev/appDevDebugProjectContainer.php line 2336
at PDO->__construct('mysql:dbname=db_platform', 'root', '****') in /var/www/Symfony/app/cache/dev/appDevDebugProjectContainer.php line 2336
at appDevDebugProjectContainer->getPdoService() in /var/www/Symfony/app/bootstrap.php.cache line 209
at Container->get('pdo') in /var/www/Symfony/app/cache/dev/appDevDebugProjectContainer.php line 3027
at appDevDebugProjectContainer->getSession_Handler_PdoService() in /var/www/Symfony/app/bootstrap.php.cache line 209
at Container->get('session.handler.pdo') in /var/www/Symfony/app/cache/dev/appDevDebugProjectContainer.php line 3053
at appDevDebugProjectContainer->getSession_Storage_NativeService() in /var/www/Symfony/app/bootstrap.php.cache line 209
at Container->get('session.storage.native') in /var/www/Symfony/app/cache/dev/appDevDebugProjectContainer.php line 3014
at appDevDebugProjectContainer->getSessionService() in /var/www/Symfony/app/bootstrap.php.cache line 209
at Container->get('session') in /var/www/Symfony/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/EventListener/SessionListener.php line 52
........
As you can see above there is no "localhost" in the config file and in the error stack trace the construct method is not passing the host and port data to the PDO class:
PDO->__construct('mysql:dbname=db_platform', 'root', '****')
I have already deleted the cache folder manually.
composer.json
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.1.0",
"doctrine/orm": ">=2.3.0,<2.4.*-dev",
"doctrine/doctrine-bundle": ">=2.1",
"doctrine/mongodb": "1.0.1",
"doctrine/mongodb-odm-bundle": "3.0.*",
"twig/extensions": "1.0.*",
"symfony/assetic-bundle": "2.1.*",
"symfony/swiftmailer-bundle": "2.1.*",
"symfony/monolog-bundle": "2.1.*",
"sensio/distribution-bundle": "2.1.*",
"sensio/framework-extra-bundle": "2.1.*",
"sensio/generator-bundle": "2.1.*",
.... more
},
Any suggestion?
Thanks in advance, Mauro
I could figure out the problem, it was the PDO service arguments in config.yml:
I had to add the host and port parameters.
Thanks for the replies.
Mauro