Laravel OpenShift Deployment Issue in database migrations

719 Views Asked by At

I am trying to deploy a Laravel 4.2 application on RedHat OpenShift. I have successfully transferred the code from GitHub but I am stuck at the database integration.

How do I run the migrations?

  • I have created a new mysql_openshift database connection with OpenShift credentials and updated the same.
  • I have a migration file in the migrations folder.
  • But on running the php artisan migrate i get the following error:

https://i.stack.imgur.com/nQbam.png

Please help!

2

There are 2 best solutions below

0
On

The Laravel 4.2 QuickStart was updated 2 days ago. The QuickStart now automatically runs php artisan migrate when you deploy changes to OpenShift. I definitely recommend switching over to using the QuickStart or updating to the latest version.

Anyways, the short answer to the problem you're seeing: your database is not configured properly in Laravel. See lines 60-70 of app/config/database.php in the Laravel 4.2 QuickStart for a reference on configuring the host/port connection info.

0
On

Your openshift db parameters are not set correctly.

Look at your config/database.php you will see how the setting in .env are used. Like before we try to get environmental variables from Openshift. The function env('DB_HOST', 'default') will take either DB_HOST from .env or use the default value in the second parameter. Since .env is excluded from version control, Laravel will take the Openshift-specific settings instead.

So put the following code in your config/app.php :

'mysql' => [
'driver'    => 'mysql',
'host'      => env('DB_HOST', getenv('OPENSHIFT_MYSQL_DB_HOST')),
'database'  => env('DB_DATABASE', getenv('OPENSHIFT_APP_NAME')),
'username'  => env('DB_USERNAME', getenv('OPENSHIFT_MYSQL_DB_USERNAME')),
'password'  => env('DB_PASSWORD', getenv('OPENSHIFT_MYSQL_DB_PASSWORD')),
'port'      => env('DB_PORT', getenv('OPENSHIFT_MYSQL_DB_PORT')),
'charset'   => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix'    => '',
'strict'    => false,],