0

I've created a php application on Openshift. Then I added a MySQL database to my app. Afterward I can see database related variables in SSH shell with env command.

However when I tried to use environment varibles to setup db connection, it does not retrun them to my php code. As a example:

<?php
echo('App: '.$_ENV["OPENSHIFT_APP_NAME"].'<br/>');
echo('Host: '.$_ENV["OPENSHIFT_MYSQL_DB_HOST"]);

OPENSHIFT_APP_NAME returns Application name correctly however OPENSHIFT_MYSQL_DB_HOST is null and host information is not available.

I also restarted my application in console. As a notice I used WinScp to directly upload my application and I'm not sure if deployment of php application needs anything more or less (like some require stuff)?

Update:

When I checked phpMyAdmin codes, I saw it have a file 'conf.d/passenv.conf' with syntax like this:

PassEnv OPENSHIFT_MYSQL_DB_PORT 

My be it help for resolving my problem.

VSB
  • 9,825
  • 16
  • 72
  • 145
  • `rhc env-list` (List all the environment variables) `rhc env-set {VARIABLE1}={VALUE1} {VARIABLE2}={VALUE2}` (Assign your own...) [Check out this link...](https://blog.openshift.com/taking-advantage-of-environment-variables-in-openshift-php-apps/) `define('DB_HOST', getenv('OPENSHIFT_MYSQL_DB_HOST'));` – zipzit Jul 20 '16 at 08:12
  • @zipzit It is supposed that they are defined already when I add new cartridge. Since they might be changes in server configuration and I should not define them manually. – VSB Jul 20 '16 at 08:19
  • Oops. Sorry if that was too subtle. Open RHC, then type `rhc env-list`, and show us what the results are. Then do a couple of `echo(getenv('OPENSHIFT_MYSQL_DB_HOST') );` (as appropriate for environment variables observed from the above env-list) and use `tail-all` command to see results from your PHP code (if using log files) . Note: `getenv..` not `$_ENV` (although from what I can tell either should work fine in PHP) – zipzit Jul 20 '16 at 08:23
  • Question: Did you create your gear with the `PHP, MySQL, and phpMyAdmin` package, or just `PHP` and then later add `MySQL`? – zipzit Jul 20 '16 at 08:38
  • @zipzit I created php and then add MySQL. – VSB Jul 20 '16 at 08:39
  • Were you able to see results of all the environment variables via either `RHC` or `ssh...` ? – zipzit Jul 20 '16 at 08:40
  • @zipzit `rhc env-list` needs `-a` param as mandatory option, however ``rhc env-list -a myapp` returns nothing. but according to https://bugzilla.redhat.com/show_bug.cgi?id=1241479 it should be like this as designed! – VSB Jul 20 '16 at 08:40
  • 1
    Not sure how much time you've already invested, but I'd be very tempted to delete the gear and try the integrated `PHP, MySQL and PhpMyAdmin` package, see if the results are better that way... Note: that option is only visible from the `PHP (See All)` link on the add a gear page. [Link here..](https://openshift.redhat.com/app/console/application_types?tag=php) – zipzit Jul 20 '16 at 08:42
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/117790/discussion-between-vsb-and-zipzit). – VSB Jul 20 '16 at 08:50

1 Answers1

0

You need to stop and start (NOT restart) your application, since you added MySQL after your application was created. use the rhc app stop and rhc app start commands.