0

I'm deploying a PHP app which uses Doctrine as ORM in Openshift. In my post_deploy action hook I run doctrine orm schema-tool to update the DB but I'm getting a Connection Timeout error. As I'm farily new to Openshift, what is the best way to setup the database on Openshift?

UPDATE I have two gears, one for the app and other for MySQL. I ssh into the app gear and ran

doctrine orm:schema-tool:update

Which results in a Connection Timeout error. If I try

  mysql -h $OPENSHIFT_MYSQL_DB_HOST
        -p $OPENSHIFT_MYSQL_DB_PORT 
        -u $OPENSHIFT_MYSQL_DB_USERNAME 
        -P $OPENSHIFT_MYSQL_DB_PASSWORD
        -

I get a prompt and the subsequent error after entering the MySQL password informed by Openshift.

Enter password: 
ERROR 1049 (42000): Unknown database '<obsfucated_password>'

UDPATE 2: As an unrelated thing pointed by Martin below, the mysql syntax is wrong. After fixing it I found that

 mysql -u $OPENSHIFT_MYSQL_DB_USERNAME
       -h $OPENSHIFT_MYSQL_DB_HOST
       -P $OPENSHIFT_MYSQL_DB_PORT
       -D $OPENSHIFT_APP_NAME 
       -p $OPENSHIFT_MYSQL_DB_PASSWORD

Results in

Enter password: 
ERROR 1045 (28000): Access denied for user 'adminjbEnwMq'@'10.63.71.68' (using password: NO)

While runnning

mysql -u $OPENSHIFT_MYSQL_DB_USERNAME -h $OPENSHIFT_MYSQL_DB_HOST -P $OPENSHIFT_MYSQL_DB_PORT -D $OPENSHIFT_APP_NAME

Connects successfully.

UPDATE 3 On the PHP side I'm running the following test code, thanks to this answer:

  <?php

    require_once "vendor/autoload.php";
    require_once "vendor/doctrine/common/lib/Doctrine/Common/ClassLoader.php";
    use Doctrine\DBAL\Configuration;

    $config = new \Doctrine\DBAL\Configuration();

    define('DB_HOST', getenv('OPENSHIFT_MYSQL_DB_HOST'));
    define('DB_PORT',getenv('OPENSHIFT_MYSQL_DB_PORT')); 
    define('DB_USER',getenv('OPENSHIFT_MYSQL_DB_USERNAME'));
    define('DB_PASS',getenv('OPENSHIFT_MYSQL_DB_PASSWORD'));
    define('DB_NAME',getenv('OPENSHIFT_GEAR_NAME'));
    $connectionParams = array(
        'dbname' => DB_NAME,
        'user' => DB_USER,
        'password' => DB_PASS,
        'host' => DB_HOST,
        'driver' => 'pdo_mysql',
    );
    $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
    var_dump($conn);
    echo $conn->query("SHOW TABLES"); 
?>

And I get the same timeout error.

Community
  • 1
  • 1
Grasshopper
  • 1,749
  • 1
  • 14
  • 30
  • i hosted a java app, and this type of things happen then the application crash but don't close the connection properly . – Saif May 05 '15 at 12:38
  • Have you tried sshing into your gear and running that post_deploy hook manually to try and debug the issue? –  May 05 '15 at 15:56
  • Also, are you using any particular PHP framework or just PHP + Doctrine? – luciddreamz May 05 '15 at 20:45
  • I'm running plain PHP with Doctrine for ORM. I did ssh into the gear and ran both doctrine's orm:schema-tool:update which resulted in the Timeout error. I also tried running "mysql --host $OPENSHIFT_MYSQL_DB_HOST --port $OPENSHIFT_MYSQL_DB_PORT --user $OPENSHIFT_MYSQL_DB_USERNAME --password $OPENSHIFT_MYSQL_DB_PASSWORD" and I get a password prompt. If I inform the password I get an error saying a database named after the password doesn`t exist. – Grasshopper May 05 '15 at 21:41
  • Can you show us your doctrine configuration? – MartinB May 06 '15 at 10:41

2 Answers2

0

I cannot help you with your doctrine question, but the mysql command syntax is actually wrong.

Usage: mysql [OPTIONS] [database]

As you can see in your output, mysql is interpreting your password as the database name.

If you want to specify the optionas as you showed above you need to add an '=' between the option and the option-value.

mysql --host=$OPENSHIFT_MYSQL_DB_HOST
      --port=$OPENSHIFT_MYSQL_DB_PORT 
      --user=$OPENSHIFT_MYSQL_DB_USERNAME 
      --password=$OPENSHIFT_MYSQL_DB_PASSWORD

If you want to add the database name to your command, the default database name is $OPENSHIFT_APP_NAME. Just add it at the end of your mysql command.

To see all the mysql options do mysql --help

MartinB
  • 231
  • 1
  • 5
0

Maybe it was because I was always working on this after 23hs, but this morning I realized I was not setting the port connection parameter. The following code works like a charm:

$dbParams = array(
      'driver'   => 'pdo_mysql',
      'host' => getenv('OPENSHIFT_MYSQL_DB_HOST')?: '127.0.0.1',
      'port'  => getenv('OPENSHIFT_MYSQL_DB_PORT')?:'3306',
      'user'     => getenv('OPENSHIFT_MYSQL_DB_USERNAME')?: 'stpe',
      'password' => getenv('OPENSHIFT_MYSQL_DB_PASSWORD')?: 'thefallen1',
      'dbname'   => getenv('OPENSHIFT_APP_NAME')?:'stpe',
  );
Grasshopper
  • 1,749
  • 1
  • 14
  • 30