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.