2

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

5
  • I know you have cleared your cache (deleted and recreated the directory?) but, silly question: the parameters.yml you show us here is the one on your server right? Commented Jan 12, 2013 at 0:26
  • Just a guess but sometimes machines don't like root to connect remotely. Maybe try a different mysql user just for kicks? Commented Jan 12, 2013 at 3:01
  • Yes, that configuration is the one on my server. The cache directory recreates automatically, I do not have root permission on the server to create it. On the other hand, yes, I have tried with another db user and it didnt work either. Commented Jan 12, 2013 at 3:17
  • @carriom so you did delete the cache directory or just run the cache clear command? Commented Jan 14, 2013 at 2:54
  • @cheesemacfly I did delete the cache directory manually because the cache:clear command executes with the mentioned PDO error. Commented Jan 14, 2013 at 3:37

2 Answers 2

6

I could figure out the problem, it was the PDO service arguments in config.yml:

services:
    pdo:
        class: PDO
        arguments:
            - "mysql:host=%database_host%;port=%database_port%;dbname=%database_name%"
            - %database_user%
            - %database_password%

I had to add the host and port parameters.

Thanks for the replies.
Mauro

Sign up to request clarification or add additional context in comments.

Comments

1

on newer versions of symfony ( > 3 ) you can simply do (in your .env file) :

DATABASE_URL=mysql://mysql_user_name:[email protected]:3306/your_database

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.