Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 ClearDB configuration on Heroku

Tags:

heroku

symfony

Can anyone explicitly tell me how to connect a my symfony2 App to ClearDB on heroku?

I got the connection string on heroku by typing

$ heroku config

but when i put the results on my parameters.yml i get a SQLSTATE[HY000] [2002] Connection refused error.

Thanks in advance

like image 624
Masinde Muliro Avatar asked Nov 01 '22 19:11

Masinde Muliro


1 Answers

This will help anyone else stuck like I was:

  1. Put your connection parameters in parameters.php instead of parameters.yml as below

    <?php
    
    // Using ClearDB for mysql database
    $db = parse_url($_ENV['CLEARDB_DATABASE_URL']); 
    $container->setParameter('database_driver', 'pdo_mysql'); 
    $container->setParameter('database_host', $db['host']); 
    $container->setParameter('database_port', '~');
    $container->setParameter('database_name', trim($db['path'], '/')); 
    $container->setParameter('database_user', $db['user']); 
    $container->setParameter('database_password', $db['pass']);
    
    // Using Mandrill to send email
    $container->setParameter('mailer_transport', 'smtp');
    $container->setParameter('mailer_host', 'smtp.mandrillapp.com');
    $container->setParameter('mailer_user', $_ENV['MANDRILL_USERNAME']);
    $container->setParameter('mailer_password', $_ENV['MANDRILL_APIKEY']);
    
    // Other settings
    $container->setParameter('locale', 'en');
    $container->setParameter('secret', 'your_secret');
    
    ?>
    
  2. Include parameters.php in your config file:

    imports: - { resource: parameters.php} 
    
like image 176
Masinde Muliro Avatar answered Nov 15 '22 09:11

Masinde Muliro