Chapters
30 Chapters
|
2:45:48
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: >=5.5.9
Subscribe to download the code!Compatible PHP versions: >=5.5.9
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
19.
vars_prompt & Environment Variables
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This tutorial is built using an older version of Symfony, but the core concepts of Ansible are still valid. New versions of Ansible may contain some features that we don't use here.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=5.5.9",
"symfony/symfony": "3.1.*", // v3.1.4
"doctrine/orm": "^2.5", // v2.7.2
"doctrine/doctrine-bundle": "^1.6", // 1.6.4
"doctrine/doctrine-cache-bundle": "^1.2", // 1.3.0
"symfony/swiftmailer-bundle": "^2.3", // v2.3.11
"symfony/monolog-bundle": "^2.8", // 2.11.1
"symfony/polyfill-apcu": "^1.0", // v1.2.0
"sensio/distribution-bundle": "^5.0", // v5.0.12
"sensio/framework-extra-bundle": "^3.0.2", // v3.0.16
"incenteev/composer-parameter-handler": "^2.0", // v2.1.2
"doctrine/doctrine-migrations-bundle": "^1.2", // v1.2.0
"snc/redis-bundle": "^2.0", // 2.0.0
"predis/predis": "^1.1", // v1.1.1
"composer/package-versions-deprecated": "^1.11" // 1.11.99
},
"require-dev": {
"sensio/generator-bundle": "^3.0", // v3.0.8
"symfony/phpunit-bridge": "^3.0", // v3.1.4
"doctrine/data-fixtures": "^1.1", // 1.3.3
"hautelook/alice-bundle": "^1.3" // v1.4.1
}
}
14 Comments
Hi!
I've a problem with environment the SYMFONY_ENV var. In my case I've called app_env instance of symfony_env. But when composer install --no-dev there is a error
TASK [Install Composer's dependencies] ***********
\n An error occurred when executing the \"'cache:clear --no-warmup'\" command: \n PHP Fatal error: Uncaught ReflectionException: Class Doctrine\Common\DataFixtures\AbstractFixture not found in /var/www/project/src/AppBundle/DataFixtures/ORM/LoadUserData.php:10
My playbook:
My project use doctrine:fixtures:load. As the docs say, I register the bundle in:
Do you know any idea that it can be ...? 😞
thanks!
Hey Juan,
Hm, at the first sight, it's correct. Let's debug a bit more. Could you SSH to your server and run "composer install" manually? Do you have the same error? Also, you could try to always install dev deps with simply "no_dev: no". Does it fix the problem? Btw, could you try it manually locally? Are you sure you don't have the same problem and fixtures could be loaded successfully locally?
Cheers!
HeyVictor
En aws server with ssh:
When I try composer install (dev) is all ok.
But when I try: composer install --no-dev
Thanks!
More info:
In my LoadUser.php
When I installed composer with --no-dev the namespaces next are wrong, because not exits Doctrine\Common\DataFixtures.
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
Yes, this sounds correct if you register DoctrineFixturesBundle in AppKernel only for dev/test environments.
Cheers!
victor First I want to thank you for all your help, I have solved the error
The installation and configuration were right, but in DoctrineFixtures classes I was using a OrderedFixtureInterface old, at the current version is different....
I'm really grateful to you
I will edit the first comment to report that the error is to another different problem than this lesson . Or if you wish, I can delete it so as not to confuse.
Thanks!
Hey Juan,
Don't worry too much about your previous comments, we'll keep them ;)
Hm, it's a bit weird that fixtures broke your prod environment even when you do not use fixtures in prod at all. But I really glad you got it working!
Cheers!
Hey Juan,
Hm, are you sure you include DoctrineFixturesBundle namespace in AppKernel for dev/test environment only? And what about your local machine? Does it work locally when you execute "composer install --no-dev"?
UPD: I can suggest you to try to upgrade Composer dependencies with "composer update". It will pull latest versions and regenerate composer.lock. Then, try to execute "composer install --no-dev" again.
Cheers!
Also, let's see SYMFONY_ENV works well, try to follow a few steps:
- SSH to AWS server
- cd /to/project/dir
- try again to install deps without importing SYMFONY_ENV, just execute: "composer install --no-dev"
- On this step you should see the error you reported, right?
- Now let's export prod environment var by executing: "export SYMFONY_ENV=prod"
- And in the same terminal tab you exported SYMFONY_ENV, execute again: "composer install --no-dev"
Do you still have that error? Or, does it work now?
Cheers!
HI victor ,
In local:
In local I have defined SYMFONY_ENV=prod
#~/.zshrc
export SYMFONY_ENV="prod"
...
PHP Fatal error: Uncaught ReflectionException: Class Doctrine\Common\DataFixtures\AbstractFixture not found in /Users/juanluisgarciaborrego/Sites/project/src/AppBundle/DataFixtures/ORM/LoadUserData.php:10
...
Fatal error: Uncaught ReflectionException: Class Doctrine\Common\DataFixtures\AbstractFixture not found in /Users/juanluisgarciaborrego/Sites/project/vendor/symfony/symfony/src/Symfony/Component/Config/Loader/FileLoader.php on line 179
...
[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command:
Fatal error: Uncaught ReflectionException: Class Doctrine\Common\DataFixtures\AbstractFixture not found in /Users/juanluisgarciaborrego/Sites/project vendor/symfony/symfony/src/Symfony/Component/Config/Loader/FileLoader.php on line 179
Symfony\Component\Config\Exception\FileLoaderLoadException: Class Doctrine\Common\DataFixtures\AbstractFixture not found in /Users/juanluisgarciaborrego/Sites/project/app/config/services.yml (which is being imported from "/Users/juanluisg
arciaborrego/Sites/project/app/config/config.yml"). in /Users/juanluisgarciaborrego/Sites/project/vendor/symfony/symfony/src/Symfony/Component/Config/Loader/FileLoader.php on line 179
Victor,
I'm trying and I think
It's all ok.
First I run ansible-playbook -i ......... with environment DEV, so it installs :
- create BD
- schema update
- fixtures load
That is good, the next, I run with environment PROD, I ansible is happy and skypped Load data fixtures and Warmup cache.
But, this I think not is the workflow correct.
Hey Juan,
I agree, that sounds not quite right workflow. In prod environment you really need to skip loading fixtures, but you still need to clear/warm up the cache, but this time with "--env=prod" option. Also, for production you won't just update schema with bin/console doctrine:schema:update, you need to run migrations instead to prevent loosing data.
Cheers!
On prod environment I got this error:
fatal: [192.168.50.8]: FAILED! => {"changed": false, "cmd": ["/var/www/project/bin/console", "hautelook_alice:doctrine:fixtures:load", "--no-interaction"], "delta": "0:00:00.080143", "end": "2018-05-10 10:27:36.079665", "msg": "non-zero return code", "rc": 1, "start": "2018-05-10 10:27:35.999522", "stderr": "\n \n [Symfony\\Component\\Console\\Exception\\CommandNotFoundException] \n There are no commands defined in the \"hautelook_alice:doctrine:fixtures\" namespace. \n Did you mean this? \n generate:doctrine
Thats because of dev dependencies in composer.json, I believe. With commented SYMFONY_ENV: "{{ symfony_env|lower }}" or dev as environment in prompt everything works fine.
NB: this error will be removed by conditional logic in a next chapter.
Hey toporovvv ,
Yes, most probably so... but to be sure you can open config/bundles.php file (app/AppKernel.php) and make sure this fixtures bundle is loaded in dev/test env only (not in prod). Actually, it's a best practice to not load fixtures in production which makes sense because you can accidentally overwrite prod data.
Cheers!
"Houston: no signs of life"
Start the conversation!