Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to set Database credentials #3

Closed
manan-jadhav opened this issue Mar 31, 2015 · 4 comments
Closed

Not able to set Database credentials #3

manan-jadhav opened this issue Mar 31, 2015 · 4 comments

Comments

@manan-jadhav
Copy link

The deploy hook is not setting DB_DATABASE, DB_USERNAME, etc. It only sets the driver.

@luciddreamz
Copy link
Owner

That's intentional - these are using the existing OpenShift Environment variables:
https://github.com/luciddreamz/laravel/blob/master/config/database.php#L59

@manan-jadhav
Copy link
Author

I already had a laavel app at my localhost. So I pushed it up with the .openshift directory.
It would be better to actually set the variables in .env instead of config file.

@luciddreamz
Copy link
Owner

Right, but why aren't you able to set database credentials? The QuickStart supports setting DB_USERNAME, DB_PASSWORD, etc by checking for the DB_USERNAME prior to checking for OPENSHIFT_MYSQL_USERNAME. Feel free to set these for local development or remote development.

I wouldn't recommend it, but if you really want to duplicate the pre-existing OpenShift environment variables feel free to replace lines 33-39 in the deploy action hook:

if [ ! -z "$OPENSHIFT_POSTGRESQL_DB_HOST" ]; then
  export DB_DRIVER="pgsql"
  export DB_HOST="$OPENSHIFT_POSTGRESQL_DB_HOST"
  export DB_PORT="$OPENSHIFT_POSTGRESQL_DB_PORT"
  export DB_DATABASE="$OPENSHIFT_APP_NAME"
  export DB_USERNAME="$OPENSHIFT_POSTGRESQL_DB_USERNAME"
  export DB_PASSWORD="$OPENSHIFT_POSTGRESQL_DB_PASSWORD"
fi
if [ ! -z "$OPENSHIFT_MYSQL_DB_HOST" ]; then
  export DB_DRIVER="mysql"
  export DB_HOST="$OPENSHIFT_MYSQL_DB_HOST"
  export DB_PORT="$OPENSHIFT_MYSQL_DB_PORT"
  export DB_DATABASE="$OPENSHIFT_APP_NAME"
  export DB_USERNAME="$OPENSHIFT_MYSQL_DB_USERNAME"
  export DB_PASSWORD="$OPENSHIFT_MYSQL_DB_PASSWORD"
fi

Then, replace lines 54-57:

if [ "$(type -t set_env_var)" == "function" ]; then
  set_env_var 'DB_DRIVER' $DB_DRIVER $OPENSHIFT_HOMEDIR/.env/user_vars
  set_env_var 'DB_PORT' $DB_PORT $OPENSHIFT_HOMEDIR/.env/user_vars
  set_env_var 'DB_DATABASE' $DB_DATABASE $OPENSHIFT_HOMEDIR/.env/user_vars
  set_env_var 'DB_USERNAME' $DB_USERNAME $OPENSHIFT_HOMEDIR/.env/user_vars
  set_env_var 'DB_PASSWORD' $DB_PASSWORD $OPENSHIFT_HOMEDIR/.env/user_vars
fi

By doing this, you're just using an environment variable to create an environment variable with the same value. The database environment variables are only used by Laravel in the config file. Some variables, like APP_ENV, tend to get used elsewhere.

@manan-jadhav
Copy link
Author

Alright. Thanks.
Btw, I installed the quickstart, and then overwrote it by pushing my local repo onto it.(git push cloud -f).
So the code in config file is MINE, not the one that is defined in QuickStart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants