1

I have a script being called by Composer that should run some database procedures. However, that script have no environment variables and thus is not connecting to the database as expected.

I tried to access the application using SSH and all the environment variables are there, accessible by the PHP command-line client.

Excerpt from the deploy output:

-----> Receiving push
#!/usr/bin/env php
All settings correct for using Composer
Downloading...

Composer successfully installed to: /srv/tmp/builddir/code/composer.phar
Use it: php /srv/tmp/builddir/code/composer.phar
       Welcome to Phundament

       Installing application...

       Array
       (
       )
       bool(false)
       bool(false)

Those three debug outputs were generated by (yes, I've created the APPLICATION_ENV var as described in the guides):

print_r($_ENV);
var_dump(getenv('CRED_FILE'));
var_dump(getenv('APPLICATION_ENV'));
igorsantos07
  • 4,456
  • 5
  • 43
  • 62
  • I also noticed that, seeing those commands' output in my live application, while CRED_FILE exists, the custom APPLICATION_ENV does not. – igorsantos07 Apr 06 '13 at 18:49
  • For PHP we do not write credentials from general add-ons or the custom config add-on into environment variables but instead only make them available via the creds.json file. This is to protect people from exposing their database and other sensitive credentials via a public phpinfo page. – pst Apr 10 '13 at 07:18
  • Hmmm so in this case I should access the application environment through the credentials file too? I would never figure that out. I noticed the yii guide cites getenv() to be working, although the code uses the credentials file correctly. This should be clear in your documentation. – igorsantos07 Apr 10 '13 at 12:31
  • I would add here that using custom config vars through that cumbersome credentials file is totally AWFUL. While I do understand to have the addons credentials there, for security, it's just horrible to discover my application environment using `$credentials['CONFIG']['CONFIG_VARS']['APPLICATION_ENV']`. This is very deep and totally uneeded. I should also add that some addons have repeated strings in their keys, such as `$credentials['MONGOLAB']['MONGOLAB_URI']`. There's no need to make sure that the URI inside MONGOLAB key is from MONGOLAB lol... – igorsantos07 Apr 10 '13 at 15:00
  • Since for e.g. Java and Ruby the credentials are exported as environment variables per default and environment variables are a flat namespace, the prefix is actually required. In the creds.json file the nesting was added primarily for readability purposes. But this discussion is getting way off topic. – pst Apr 10 '13 at 18:37
  • I agree it's getting out of topic, and that's why I usually find weird when companies try to use community forums for user support (: – igorsantos07 Apr 11 '13 at 00:51
  • Although, I still must add that I see little reason for the prefix appear in the creds.json file. After all, it's a different way of accessing the information, right? So it would make sense to see env vars namespaced and the json object with an hierarchical organization only, without that cluttering prefixes. – igorsantos07 Apr 11 '13 at 00:54
  • Oh. And yet I see no reason for being unable to access the variables configured on config.free add on in the environment. I can understand protecting the addons credentials, but as those variables are mine, I should know what to do with them, right? I say that because all the other PaaS that I have already used give us a much cleaner way to set env vars - a quite common task on app development. – igorsantos07 Apr 11 '13 at 00:56

1 Answers1

2

This is correct. During the push and building of the image, no Add-on credentials are available. To run database migrations or similar scripts I suggest you use the cctrlapp run command. You can easily script this together with a push and deploy command.

pst
  • 1,414
  • 11
  • 22
  • 1
    Thanks! Any special tip about env vars on normal application run, as mentioned in my comment? – igorsantos07 Apr 09 '13 at 13:52
  • It depends on the language if env vars are enabled or disabled by default. You can always overwrite the default behaviour. https://www.cloudcontrol.com/dev-center/platform-documentation#enabling/disabling-credentials-environment-variables – pst Jun 02 '15 at 09:59