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

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.

Related

Using Symfony Doctrine Migrations with Gitlab CI: GitLab CI interprets "Nothing to migrate" as error

We are using the Doctrine migrations bundle for update database in our deployment process. Currently, we are switching to Gitlab-CI.
The problem: The CI is aborting the deployment process because the output of command php sf doctrine:migrations:diff contains stderr.
The part of our .gitlab-ci.yml:
deploy_live:
type: deploy
environment:
name: live
url: 1.2.3.4
script:
- ssh root#1.2.3.4 "cd /var/www/html/ && git pull origin master && exit"
- ssh root#11.2.3.4 "cd /var/www/html/ && composer install -n && exit"
- ssh root#1.2.3.4 "cd /var/www/html/ && php sf doctrine:migrations:diff --env=prod && exit"
- ssh root#1.2.3.4 "cd /var/www/html/ && php sf doctrine:migrations:migrate -n --env=prod && exit"
- 'ssh root#1.2.3.4 "cd /var/www/html/ && chown www-data:www-data . -R && exit"'
only:
- master
Output of Gitlab CI:
$ ssh root#1.2.3.4 "cd /var/www/html/ && php sf doctrine:migrations:diff --env=prod && exit"
#!/usr/bin/env php
In NoChangesDetected.php line 13:
No changes detected in your mapping information.
doctrine:migrations:diff [--configuration [CONFIGURATION]] [--db-configuration [DB-CONFIGURATION]] [--editor-cmd [EDITOR-CMD]] [--filter-expression [FILTER-EXPRESSION]] [--formatted] [--line-length [LINE-LENGTH]] [--check-database-platform [CHECK-DATABASE-PLATFORM]] [--db DB] [--em [EM]] [--shard SHARD] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>
ERROR: Job failed: exit code 1
This may be a bug, but maybe it can be circumvented?
FYI: sf is a symlink to bin/console.
I just found a solution:
move the commands excecuted directly from the gitlab-ci.yml file unter script to an shell script deploy.sh
move this script via scp to the server
gitlab-ci.yml
deploy_live:
type: deploy
environment:
name: live
url: 1.2.3.4
script:
- scp deploy.sh root#1.2.3.4:/var/www/html/
- ssh root#1.2.3.4 "cd /var/www/html/ && chmod +x deploy.sh && ./deploy.sh && exit"
only:
- master
deploy.sh
cd /var/www/html/
git add --all
git commit -m "changes"
git pull origin master
composer install -n
php sf doctrine:cache:clear-metadata --env=prod
php sf doctrine:migrations:diff --env=prod
php sf doctrine:migrations:migrate -n --env=prod
php sf cache:clear --env=prod
exit
They added option for such case: --allow-no-migration - can you try it?
see: https://github.com/doctrine/migrations/blob/ebd2551c7767375fcbc762b48d7dee4c18ceae97/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php#L64

Twig_Error_Loader - directory does not exist

I have this error when deleteing cache.
sudo php app/console cache:clear --env=prod --no-debug
[Twig_Error_Loader]
The "/Users/whitebear/CodingWorks/httproot/myapp/vendor/symfony/swiftmailer-bundle/Symfony/Bundle/SwiftmailerBundle/Resources/views" directory does not exist ("/Use
rs/whitebear/CodingWorks/httproot/myapp/vendor/symfony/swiftmailer-bundle/Symfony/Bundle/SwiftmailerBundle/Resources/views").
I deleted all vendor/* and reinstalled by composer, but this error continues.
sudo php app/console cache:clear
This command shows no error.
Remove cache manually - rm -rf var/cache/*
Clean spooled emails rm -rf SPOOL_DIRECTORY/*, by default rm -rf var/spool/*
Both from project root directory.

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

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

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/*

Resources