getenv('SYMFONY_ENV') is empty in app/console from composer install, but OK elsewhere - symfony

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 ?

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

Related

Command failed when running ghost start

Fresh install, trying to run ghost start I get the following error:
Debug Information:
OS: Raspbian, v8.0
Node Version: v6.13.0
Ghost-CLI Version: 1.5.2
Environment: production
Command: 'ghost start'
An error occurred.
Message: 'Command failed: /bin/sh -c systemctl is-active ghost_blog-dev
unknown
'
Stack: Error: Command failed: /bin/sh -c systemctl is-active ghost_blog-dev
unknown
at makeError (/usr/lib/node_modules/ghost-cli/node_modules/execa/index.js:169:9)
at module.exports.sync (/usr/lib/node_modules/ghost-cli/node_modules/execa/index.js:338:15)
at handleShell (/usr/lib/node_modules/ghost-cli/node_modules/execa/index.js:116:9)
at Function.module.exports.shellSync (/usr/lib/node_modules/ghost-cli/node_modules/execa/index.js:361:43)
at SystemdProcessManager.isRunning (/usr/lib/node_modules/ghost-cli/extensions/systemd/systemd.js:88:19)
at Instance.running (/usr/lib/node_modules/ghost-cli/lib/instance.js:120:34)
at StartCommand.run (/usr/lib/node_modules/ghost-cli/lib/commands/start.js:28:22)
at precheck.then (/usr/lib/node_modules/ghost-cli/lib/command.js:159:52)
at process._tickCallback (internal/process/next_tick.js:109:7)
at Module.runMain (module.js:613:11)
at run (bootstrap_node.js:387:7)
at startup (bootstrap_node.js:153:9)
at bootstrap_node.js:500:3
Code: 3
If I manually run the command that is says failed it seems to execute without error though I am not sure what it does. I assume it has something to do with checking with nginx if ghost has actually started or not.
Any suggestions would be very helpful! Thank you!
I faced with the same problem. You should add your service file to etc directory also as symbolic link using the following command:
sudo ln -sf /var/www/html/your-blog/system/files/ghost_blog-yourblog.service /etc/systemd/system/ghost_blog-yourblog.service
After adding this, you should execute the following commands:
sudo systemctl stop ghost_blog-yourblog.service
sudo systemctl start ghost_blog-yourblog.service
Then, I hope you'll see 'active' result for is-active command.

Error during composer install --no-dev option in ElasticBeanstalk with Symfony 2

I am deploying Symfony 2 app in ElasticBeanstalk but when I run this I get an error saying
ERROR: Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle class not found.
I have this config.
container_commands:
110-remove-pg:
command: "yum remove -y php56-pgsql"
120-install-pglib:
command: "yum install -y postgresql94-libs"
130-install-pg:
command: "yum install -y php56-pgsql"
140-clear-folder:
command: "rm -rf var/cache/* var/logs/* var/sessions/*"
150-folder-config:
command: "source .ebextensions/bin/folder.sh"
160-pre-cache-clear:
command: "php bin/console cache:clear --env=prod --no-debug"
170-run-export:
command: "export SYMFONY_ENV=prod"
180-composer-install-no-dev:
command: "composer.phar install --no-dev --optimize-autoloader"
190-post-cache-clear:
command: "php bin/console cache:clear --env=prod --no-debug"
200-assets-dump:
command: "php bin/console assetic:dump --env=prod --no-debug"
210-remove-dev-app:
command: "rm web/app_dev.php"
Seems like it is still triggering DEV option. If I remove --no-dev option it works fine. But I do not want DEV packages. Is there anyway to resolve this issue.
Alright I found the solution of this problem. Apparently you need to put
SYMFONY_ENV=prod
In environment variables list for this to work.

Unable to install Sylius with Composer

With composer, i tried to install Sylius via sylius/sylius and sylius/sylius-standard.
Installations have both ended like this :
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-update-cmd event terminated with an exception
[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command.
It happens just after the parameters.ini initialization.
And after, the command line doesn't work (example : "app/console list" return nothing) although I'm in the project root directory.
Any idea, please ? Thanks.
I've gotten this error ( I'm not sure if it's the same place where your getting it ) and developed a solution that seems to work. Instead of running app/console cache:clear ( which I think gets run at the end of the composer install ), I run a bash script that opens the permissions before and after.
sudo sh clearCache
Contents of clearCache:
#!/bin/bash
chmod -R 777 app/cache/ app/logs/
su www-data -c "app/console cache:clear -e dev"
chmod -R 777 app/cache/ app/logs/
su www-data -c "app/console cache:clear -e prod"
chmod -R 777 app/cache/ app/logs/
I think I got this message during a composer install and was still able to continue via cd Sylius and app/console sylius:install. Just run this before and after installing and updates.

error about dependencies again and again

I took my project to another local computer and Im getting this error after requesting app_dev.php:
You must set up the project dependencies by running the following
commands: curl -s http://getcomposer.org/installer | php php
composer.phar install.
So I run those commands but the error is the same again...
You sure you use 2.0 version? Because composer is used in symfony 2.1
Can you show logs which occur when executing php composer.phar install?
Else try to:
Remove extra php word in curl -s http://getcomposer.org/installer | php php composer.phar install
Delete cache and make cache dir writable: sudo rm -rf app/cache/* && chmod a+rwx -R app/cache/*

symfony2 app console: no available command

After HDD crash, I had to reimport my symfony2 app into Eclipse from my SVN server.
After syncing everything, I can't use the console anymore. I only get 2 commands : list and help.
I tried:
php bin/vendors install --reinstall
At the end, I got the following message:
[InvalidArgumentException]
There are no commands defined in the "assets" namespace.
[InvalidArgumentException]
There are no commands defined in the "cache" namespace.
My configuration is pretty simple:
- ubuntu server 11.04 (64bits)
- virtualbox OSE
How can I fix it?
Here is the result of app/console list command:
oc#ubuntu-server:/var/www/projets/Simoov2/src$ app/console list
Symfony version 2.0.0-RC4 - app/dev/debug
Usage:
[options] command [arguments]
Options:
--help -h Display this help message.
--quiet -q Do not output any message.
--verbose -v Increase verbosity of messages.
--version -V Display this program version.
--ansi Force ANSI output.
--no-ansi Disable ANSI output.
--no-interaction -n Do not ask any interactive question.
--shell -s Launch the shell.
--env -e The Environment name.
--no-debug Switches off debug mode.
Available commands:
help Displays help for a command
list Lists commands
OK. As I thought, this is not related to symfony2 but related to virtualbox mounting system.

Resources