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!
16.
Symfony Console Commands
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
}
}
56 Comments
fatal: [127.0.0.1]: FAILED! => {"changed": true, "cmd": ["/var/www/project/bin/console", "doctrine:database:create", "--if-not-exists"], "delta": "0:00:00.024293", "end": "2020-02-22 12:08:42.155989", "msg": "non-zero return code", "rc": 255, "start": "2020-02-22 12:08:42.131696", "stderr": "PHP Warning: require(/var/www/project/app/../vendor/autoload.php): failed to open stream: No such file or directory in /var/www/project/app/autoload.php on line 9\nPHP Fatal error: require(): Failed opening required '/var/www/project/app/../vendor/autoload.php' (include_path='.:/usr/share/php') in /var/www/project/app/autoload.php on line 9", "stderr_lines": ["PHP Warning: require(/var/www/project/app/../vendor/autoload.php): failed to open stream: No such file or directory in /var/www/project/app/autoload.php on line 9", "PHP Fatal error: require(): Failed opening required '/var/www/project/app/../vendor/autoload.php' (include_path='.:/usr/share/php') in /var/www/project/app/autoload.php on line 9"], "stdout": "", "stdout_lines": []}
Hey dhruv,
From the output, I see the problem is that you don't have Composer dependencies installed. Please, make sure you run "composer install" first before calling any Symfony console commands.
I hope this helps!
Cheers!
Thanks
Hey dhruv,
It looks like I got double "thanks" from you on this problem :D did you hit this problem again? ;) Anyway, glad it was useful one more time for you!
Cheers!
thanks
For those who faced an issue with
hautelook/alice-bundle:You can use my fork
https://github.com/ksxauh/ansible.gitwith a fix as a Git repository in the "Checkout Git repository" ansible taskP.S. I've created a PR to the original repo as well: https://github.com/knpuniversity/ansible/pull/11 //cc
Missing repo Explanation: https://github.com/nelmio/alice/issues/1089
Hey Kirill,
Thanks for sharing it! Though the hautelook/alice-bundle is now should be available again, see: https://packagist.org/packages/hautelook/alice-bundle
Cheers!
fatal: [127.0.0.1]: FAILED! => {"changed": true, "cmd": ["/var/www/project/bin/console", "--if-not-exists", "doctrine:database:create"], "delta": "0:00:00.120540", "end": "2020-02-26 16:37:40.124195", "msg": "non-zero return code", "rc": 1, "start": "2020-02-26 16:37:40.003655", "stderr": "\nIn AbstractMySQLDriver.php line 115:\n \n An exception occured in driver: SQLSTATE[HY000] [1698] Access denied for us \n er 'root'@'localhost' \n \n\nIn PDOConnection.php line 47:\n \n SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' \n \n\nIn PDOConnection.php line 43:\n \n SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' \n \n\ndoctrine:database:create [--shard SHARD] [--connection [CONNECTION]] [--if-not-exists] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>", "stderr_lines": ["", "In AbstractMySQLDriver.php line 115:", " ", " An exception occured in driver: SQLSTATE[HY000] [1698] Access denied for us ", " er 'root'@'localhost' ", " ", "", "In PDOConnection.php line 47:", " ", " SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' ", " ", "", "In PDOConnection.php line 43:", " ", " SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' ", " ", "", "doctrine:database:create [--shard SHARD] [--connection [CONNECTION]] [--if-not-exists] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>"], "stdout": "", "stdout_lines": []}
____________
a new error occured after i installed composer dependencies.
Hey dhruv sahu!
Hmm, it looks like your database password is incorrect for your database:
This is happening when you're running
bin/console doctrine:database:create. Have you configured your database credentials in.env(or parameters.yml, depending on your Symfony version) before you've run this command?Cheers!
ERROR! Syntax Error while loading YAML.
mapping values are not allowed in this context
The error appears to be in '/etc/ansible/playbook.yml': line 114, column 16, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Create DB if not exists
command: "{{ symfony_console_path }} doctrine:database:create --if-not-exists"
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
He ydhruv,
Hm, this sounds like indentation problems, no? Anyway, were you able to fix this yourself? Quotes helped you?
Cheers!
no nothing worked
please rectify this error
Hey dhruv,
Sorry, but what error exactly are you talking about? Could you give us a bit more context, please?
Cheers!
Hi guys. Task 'Execute migrations' give me an error: fatal: [192.168.33.10]: FAILED! => {"changed": true, "cmd": ["/var/www/ansible_project/bin/console", "doctrine:migrations:migrate", "--no-interaction"], "delta": "0:00:00.182210", "end": "2017-05-23 21:41:51.013178", "failed": true, "rc": 1, "start": "2017-05-23 21:41:50.830968", "stderr": "\n \n [Symfony\\Component\\Console\\Exception\\CommandNotFoundException] \n There are no commands defined in the \"doctrine:migrations\" namespace. \n Did you mean one of these? \n doctrine \n doctrine:cache \n doctrine:database \n doctrine:generate \n doctrine:mapping \n doctrine:query \n doctrine:schema \n ", "stderr_lines": ["", " ", " [Symfony\\Component\\Console\\Exception\\CommandNotFoundException] ", " There are no commands defined in the \"doctrine:migrations\" namespace. ", " Did you mean one of these? ", " doctrine ", " doctrine:cache ", " doctrine:database ", " doctrine:generate ", " doctrine:mapping ", " doctrine:query ", " doctrine:schema ", " "], "stdout": "", "stdout_lines": []}
I edited the composer.json: "doctrine/doctrine-migrations-bundle": "1.0.0",
"doctrine/migrations": "1.0.1" AND added in the AppKernel.php this line: new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(). How it resolve? Thanks
Hey Евгений,
Don't you forget to run "composer update" after changing the composer.json file? Because if you change composer.json manually - then you still have outdated composer.lock file, so running "composer install" has no effect.
Maybe there's a difference between versions. Could you try to install the latest version of it? To install and enable the latest version correctly you may follow the installation guide here: https://symfony.com/doc/cur... . And also try to clear the cache and run this command directly on your VM first.
Cheers!
Just blow out your projects dir in the VM and re-run Ansible. Ansible isnt actually pulling the new project files in. You can see that by looking at app/AppKernel.php. The migrations and haute bundles arent even registered because you still have the symfony standard code. Once you blow out the project dir it'll see the change, pull the new code and Composer will install the new packages.
Hi guys,
hmm, no one of your suggestions helps me:
`fatal: [192.168.19.147]: FAILED! => {"changed": true, "cmd": ["/var/www/project/bin/console", "doctrine:migrations:migrate ", "--no-interaction"], "delta": "0:00:00.113318", "end": "2020-10-25 14:55:22.904648", "msg": "non-zero return code", "rc
": 1, "start": "2020-10-25 14:55:22.791330", "stderr": "\n
Tested with Ubuntu Xenial, Bionic and Focal Fossa, Sym 3.4.45, Ansible 2.9.x, PHP7.4, PHP7.1...
adding this
` - name: Install Composer requirements for migrations
But it won't work. What should I do?
Hey Axel,
From the output I see that you don't have "doctrine:migrations:migrate" command. Please, make sure you have it installed via Composer and enabled in app/AppKernel.php. Also, make sure it's installed and enabled for the environment in which you're trying to execute this command. For debugging, you literally may want to ssh into the container and execute that command manually to see the error.
Cheers!
Encountered the same problem. Took me a lot of digging, but it turns out I was somehow still getting the Symfony default project used earlier in the tutorial (which of course didn't have the right dependencies or had them enabled in AppKernel.php). Nuking everything in /var/www/project (including the .git folder) fixed it.
Hey Uiuytio,
Thanks for sharing your workaround with others!
Cheers!
Hi guys,
I am having some problems when trying to create the DB from the playbook.
TASK [Create DB if not exists] ************************************************************************************************************************************************************************************************<br />fatal: [192.168.33.11]: FAILED! => {"changed": false, "cmd": "/var/www/project/bin/console doctrine:database:create --if-not-exists", "msg": "[Errno 13] Permission denied: b'/var/www/project/bin/console'", "rc": 13}<br />My .env is fine and when I ssh to the VM I can create the DB manually but with the playbook it seems quite difficult.
Why does it work when I ssh to the VM but not over the playbook? I am supposed to be the same user!
Hey Sayil,
Hm, could you check its permissions? Most probably you don't have executable permissions on it. Also, are you sure the user is the same and you run it without sudo when ssh-ed to the server?
Btw, you can try to add php in front of the command, it might help. Or, just simply try to set permissions that allows execution.
I hope this helps!
Cheers!
I also added a task before the DB is created to make sure that bin/console has permissions, looks like this:
`
become: true
shell: 'chmod 0777 /var/www/project/bin/console'
`
Hey Sayil,
OK, and it still does not work? I'd recommend you to use file module instead: https://docs.ansible.com/an... - see examples below how to change permissions.
So, it's weird as for me, if you set 777 it should just work. Could you double check it has 777 after this task?
Cheers!
Hi Victor,
thanks for answering.
I checked my permissions and changed the bin/console ones. I still have the same problem but a bit different. Now this is the result I am getting:
<br />TASK [Create DB if not exists] ************************************************************************************************************************************************************************************************<br />fatal: [192.168.33.11]: FAILED! => {"changed": false, "cmd": "/var/www/project php bin/console doctrine:database:create --if-not-exists", "msg": "[Errno 13] Permission denied", "rc": 13}<br />It does not show where the permissions where denied like in the first message. Which permissions should I change?
When I ssh into the VM I can create the DB with the vagrant user and without using sudo.
I changed all the permissions in /var/www/project to try to find the solution but I still get the same message.
What am I missing here? Any Ideas?
I also added the php before the bin/console but still no.
Hey Sayil,
Hm, how do you create DB when you ssh-ed into the VM? Did you use "mysql" or "bin/console doctrine:database:create" command? It makes me think that probably you your DB credentials are incorrect? So, you don't have permissions to create DB, not execute that bin/console. Please, double check that you set DB permissions correctly for your VM machine
Cheers!
Hi Victor,
I create the database with the exact same command from inside the VM, "php bin/console doctrine:database:create". That's why I don't understand what is hapening when I try to create it with the playbook.
After I yhe task to change permissions I still have 777 so I don't understand.
Any ideas?
Thanks in advance!
Hey @Sayil!
Hmm, this is trick! I have 2 questions/comments:
1) If you SSH into the machine, are you able to run the
php bin/console doctrine:database:create? I think the answer is yes (you said so in your previous comment) but I wanted to be absolutely sure :).2) Are you using the same SSH user for your Ansible script as when you SSH in manually? Again, my guess is "Yes", but I wanted to check ;).
3) Are you able to, for example, do tasks that look like this in ansible?
4) Finally, while I can't explain why you can ssh in and run the command but Ansible cannot, one thing that could be affecting the permissions are network mounts. If your project directory is shared between your host and guest machine, then sometimes setting permissions in your VM is strange... because the file actually exists on your host machine (and is mounted as a network mount inside your VM). It's just something to keep in mind.
Let me know if you find anything! Good luck!
Cheers!
Hi Ryan,
Thank you for your answer.
Yes, I can run the the
php bin/console doctrine:database:createwhen I ssh into the VM. This was the only way of creating the DB and continue with the tutorial.Yes, I checked again and it is the same user, in my case <i>vagrant</i> user.
When I ssh into the VM I am able tu run the two commands you suggested without any problems.
I played with the permissions of most files in the VM ans still nothing. I noticed that some of them changed after running the playbook so I changed them in the playbook before creating the DB but nothing.
I will keep looking for the answer and let you know if I find anything.
Thanks for all the support!
Cheers.
Hey @Sayil!
I wonder what happens if you ssh into your machine, check the permissions, run
chmod -R 777and then check the permissions immediately after. You may notice that even this seems to not change the permissions. In that case, I would really think that you are hitting a permissions issue because the directory is a "network" directory. It might help you dig ;).Cheers!
If you face a problem "There are no commands defined in the \"doctrine:migrations\" namespace. \n Did you mean one of these?", whick I and there got after a first playbook execution in this tutorial, you need to delete /var/www/project folder. Because, I suppose, Ansible do not clean it after a changing repo path in a "Checkout Git repository" task. An after that I hadn't any issues with cache - just a proper look of MooTube on url http://mootube.l/
Hey toporovvv ,
Thanks for sharing your solution with others!
Cheers!
Wait do you need the directory's all the way to var or just the file inside project?
I'm quite confused.
Hey Emin,
You need to specify the full path to the directories / files, because each Ansible command is isolated, so if you change the dir in one step, in another step your command still will be executed in the home directory. So, Ansible do not understand the "project" and each step starts from the home directory. But each step may have "args" option where you can change dir with "chdir" sub-option, then, in the module, you can specify a path relative to the changed dir. See examples for "command" module: https://docs.ansible.com/an...
Cheers!
Hey Victor,
Yes thank you for the fast reply now i understand it better but for this to work do i delete it al they to /var/ or only stuff inside /var/www/project?
Cheers!
Hey Emin,
Could you clarify what are you trying to do, please? It depends on what you need.
Cheers!
Hey Victor,
What i mean is do i need to delete the whole /var/www/project map in the way that the path needs to be created again or only in the project file.
Hey Emin,
I suppose you mean this step:
If so - the answer is no, you don't need to delete the /var/www/project/ directory on each run, because in this step Ansible whether create this folder of it does not exist or just skip this step if it's already created. So, it's like Ansible just make sure that this folder always exists and have proper owner/group permissions and that's it.
Cheers!
Hey Victor,
Aah i see now i get it thank man! :)
Cheers!
You're welcome! Glad you've figured it out.
Cheers!
Hello guys. Problem with git checkout task. After changing repo url it fails with message "Could not determine remote revision for HEAD". Debug log - https://pastebin.com/DdF49Hqm
What could be the reason?
Thanks!
Hey mlavrik ,
It's weird enough. Did you change the repo link to another repository? I think pointing the version could fix it. Try:
Where "master" is a branch which you want to checkout.
If it doesn't help, please, try to connect to the remove host manually ("vagrant ssh" if you're using VM) and drop the repository folder at all with "rm -rf" command. Then run the playbook - Ansible try to pull the whole repo again without problem I think.
Cheers!
Thanks! Adding version parameter helps.
I'm getting this error -> There are no commands defined in the "doctrine:migrations" :(
The only thing that helped me was restart the host.
Hey Dayron,
Hm, that's a bit weird that you have to restart the host, clearing the cache should be enough. But I'm glad you solved it! And thanks for sharing your solution with other users
Cheers!
Hi guys: for some reason the CSS is off... Is it because we did not configure boostrap theme in ansible?
Hey Jian,
Hm, try to re-install the assets again with "./bin/console assets:install". Does it fix the CSS problem? Actually, this command executes during the "composer install", at the end of it. But if due to the some reason "composer install" command failed it won't be run. Also, try to clear the cache: dev/prod, depends on what environment you're using.
Cheers!
"Houston: no signs of life"
Start the conversation!