Reputation: 330
To deploy my Symfony app on production I run the following command in a bash script:
php composer.phar install --no-dev --optimize-autoloader
And I got the following error :
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-install-cmd event terminated with an exception
An error occurred when executing the "'cache:clear --no-warmup'" command.
This is because getenv('SYMFONY_ENV') in the app/console returns an empty value, while executing the commands from composer.json post-install-cmd. Therefore the $env value is not set to prod but to dev (default one).
However, the SYMFONY_ENV value is ok.
In the terminal, if I run:
printenv SYMFONY_ENV
It prints prod
If I run:
php -r "print_r(getenv('SYMFONY_ENV'));"
It prints prod
What I am missing or doing wrong ?
Upvotes: 2
Views: 3413
Reputation: 330
I just realized that I was running
sudo php composer.phar install --no-dev --optimize-autoloader
instead of
php composer.phar install --no-dev --optimize-autoloader
In my case (ubuntu 14.04), I had defined SYMFONY_ENV in /etc/environment and I thought it was accessible for all users, but it's not the case for sudo. I solved my problem running my command without sudo (because it had no reasons to be).
Another solution could be to run sudo -E php ...
to preserve the user environment as suggested here : https://askubuntu.com/questions/161924/how-do-i-set-persistent-environment-variables-for-root
Upvotes: 4