How to set environment variable before running script inside hooks/install?

30,814

HOME isn't set in the Juju hooks, only a few environment variables are.

You should be able to just run

COMPOSER_HOME="/path/you/want/to/be/home" php composer.phar install

which will set the environment variable before executing php.

Share:
30,814

Related videos on Youtube

Amit
Author by

Amit

Updated on September 18, 2022

Comments

  • Amit
    Amit almost 2 years

    I am create a simple charm to get my symfony2 webapp from git and deploy it on ec2.

    After getting the source from git, I want to run composer to resolve dependencies but I keep getting this error:

    INFO juju context.go:221 worker/uniter: HOOK   The HOME or COMPOSER_HOME environment variable must be set for composer to run correctly
    

    I am running composer using below command inside my hooks/install script

    juju-log "Running composer"
    /usr/bin/php composer.phar install
    

    I also tried

    juju-log "Running composer"
    COMPOSER_HOME=${app_dir};/bin/bash -c "/usr/bin/php composer.phar install"
    

    How can I set HOME or COMPOSER_HOME so that this command can be executed?

    • Jorge Castro
      Jorge Castro almost 11 years
      Please contact me (link in my profile page), I'd love to work with you on getting a symfony workflow in Ubuntu!
    • Amit
      Amit almost 11 years
      Sure @JorgeCastro, I will email you once my charm is complete.
  • Amit
    Amit almost 11 years
    Thanks Marco. That worked. I was trying similar but was giving ; before php, that should have also worked. COMPOSER_HOME=${app_dir} ; /usr/bin/php composer.phar install
  • Michael Gundlach
    Michael Gundlach almost 11 years
    No, the ; won't make COMPOSER_HOME an environment variable, just a variable, You would need export COMPOSER_HOME=${app_dir}; the export makes it an environment variable. What I've done is just set it as an environment variable for just that command.