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!
11.
Installing Composer & the script Module
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
}
}
24 Comments
Hi Guys, I'm on a trouble with installing composer on EC2. I'm writting here because it's error related on previous comments:
skipping: [192.168.33.10]<br />fatal: [18.203.185.87]: FAILED! => {"changed": true, "failed": true, "rc": 1, "stderr": "Shared connection to 18.203.185.87 closed.\r\n", "stdout": "/home/ubuntu/.ansible/tmp/ansible-tmp-1566331749.55-41571300702954/install_composer.sh: 4: /home/ubuntu/.ansible/tmp/ansible-tmp-1566331749.55-41571300702954/install_composer.sh: php: not found\r\n/home/ubuntu/.ansible/tmp/ansible-tmp-1566331749.55-41571300702954/install_composer.sh: 5: /home/ubuntu/.ansible/tmp/ansible-tmp-1566331749.55-41571300702954/install_composer.sh: php: not found\r\nERROR: Invalid installer signature\r\nrm: cannot remove 'composer-setup.php': No such file or directory\r\n", "stdout_lines": ["/home/ubuntu/.ansible/tmp/ansible-tmp-1566331749.55-41571300702954/install_composer.sh: 4: /home/ubuntu/.ansible/tmp/ansible-tmp-1566331749.55-41571300702954/install_composer.sh: php: not found", "/home/ubuntu/.ansible/tmp/ansible-tmp-1566331749.55-41571300702954/install_composer.sh: 5: /home/ubuntu/.ansible/tmp/ansible-tmp-1566331749.55-41571300702954/install_composer.sh: php: not found", "ERROR: Invalid installer signature", "rm: cannot remove 'composer-setup.php': No such file or directory"]}As you can see, on vagrant machine it is working fine, but on EC2 it is not correct signature... how I can fix that?
It is a 16.04 ubuntu ec2 instance.
Thanks!
Hey Alex,
Do you have PHP installed on your EC2? It sounds like you don't have "php" executable command. Could you manually ssh-ed to the EC2 and run "php --version". If you don't have a PHP yet - you need to install it first, otherwise "install_composer.sh" won't work I think.
Cheers!
Ups, that was! my fault! I was executing the command with -t deploy... so provisioning tasks were called anymore...Thanks!
Hey,
Once i run the playbook i get the following error
`fatal: [192.168.33.10]: FAILED! => {"changed": true, "cmd": ["mv", "composer.phar", "/user/local/bin/composer"], "delta": "0:00:00.005364", "end": "2018-12-27 08:50:50.294032", "msg": "non-zero return code", "rc": 1, "start": "2018-12-27 08:50:50.288668", "stderr": "mv: cannot move 'composer.phar' to '/user/local/bin/composer': No such file or directory", "stderr_lines": ["mv: cannot move 'composer.phar' to '/user/local/bin/composer': No such file or directory"], "stdout": "", "stdout_lines": []}
`
I did it like you guys told me.
Cheers!
Hey Emin,
Looks like you don't have "composer.phar" file. Could you make sure you download the "composer.phar" to successfully. And make sure you name the downloaded file as "composer.phar".
Cheers!
UPDATE: i made a new task to create a directory so it has one but once i did that
i get the following error:
`
fatal: [192.168.33.10]: FAILED! => {"changed": false, "msg": "file (/usr/local/bin/composer) is absent, cannot continue", "path": "/usr/local/bin/composer", "state": "absent"}
i think it does this because the folder already exist.
Hey Emin,
Wait, what folder exactly did you create? I suppose the problem was that you didn't have composer.phar file, so the problem was not in folder.
Cheers!
Het victor,
When i checked my vagrant box i saw that i did not have the directory "/usr/local/bin/composer" and i did have the composer.phar installed but i created a task just to make a directory so it could find the directory.
Cheers!
Hey Emin,
But that's incorrect! The "/usr/local/bin/composer" is not a directory but file. Basically, with that command we rename "composer.phar" file to "composer" (i.e. without ".phar" extension) and move it to the "/usr/local/bin/" directory that I bet you have. So, the problem is that command was not able to find composer.phar file to do this operation. Now you need to remove that "/usr/local/bin/composer" directory you created and make sure that "composer.phar" file exists. The only folder you need to have is "/usr/local/bin/" only.
Cheers!
Hey Victor,
Yes it works now but to run composer in need to type /usr/local/bin/composer to use it the composer and in the video it's only composer and it works so that's where i get confused a bit.
Cheers!
Hey Emin,
Hm, it depends on your OS probably. The "/usr/local/bin/" folder should be in the PATH env variable, so you can it globally. In some systems it might be "/usr/bin/". You can try to move the file there, i.e. the path should be "/usr/bin/composer". Or you need to add "/usr/local/bin/" to the PATH env var. Actually, just run "echo $PATH" and you'll see what global executable paths you have. Btw, you said that executing "/usr/local/bin/composer" works for you, but what error do you see when try to execute just "composer"?
Cheers!
Hey Victor,
No command 'composer' found, did you mean:
Command 'compose' from package 'mime-support' (main)
composer: command not found
but in the direcotry "/user/local/bin/composer" i see the composer and composer.phar both in there. so i'm getting a bit confused now with this.
Cheers!
Hey Emin,
Wait wait, what path exactly? :) you wrote "/user/local/bin/composer" but it's incorrect, it should be "/usr/local/bin/composer" - notice that usr! And what about "echo $PATH" output??
Cheers!
Hey Victor,
OMG really it works now i hate it when i miss type something and don't know where the error is comming from
:(. but yeah thank you man i works perfectly now. I need a break now from coding for an hour.
Cheers man !
Hey Emin,
Lol, I mentioned that *exact* path a few times! :) No problem! I'm glad we found the problem and it works now ;)
Cheers!
Hi guys:
Is there way we can roll back the task. Say I don't need composer, and can I roll back to previous state. I tried to delete the task and run again, composer still there/:
Hey jian su!
There's no native rollback in Ansible. As you know, the purpose of the tasks/playbook is to put your server in a specific "state". If you don't have any tasks related to Composer suddenly, then your playbook basically doesn't have any opinion about the "state" of Composer. It does nothing :). If you did really care about the state or something, then you should actually add a task to make sure it's not installed. I'm not suggesting you do this - because you probably don't care enough - but that's the official answer :). For example, the
aptmodule allows you to set thestatetoabsent... which you would use if you actually wanted to make sure that something was not installed.And of course, you can always start from a fresh server. But any specific rollbacks are up to you (and kind of need to be - Ansible wouldn't natively know how to rollback the Composer installation anyways).
Cheers!
I'm hitting a weird snag with the script module. Note, I am on windows linux subsystem. When I run the Install Composer step outlined above, I'm getting this error:
TASK [Download Composer] ********************************************************fatal: [192.168.33.20]: FAILED! => {"changed": true, "msg": "non-zero return code", "rc": 127, "stderr": "Shared connection to 192.168.33.20 closed.\r\n", "stdout": "/bin/sh: 1: /home/vagrant/.ansible/tmp/ansible-tmp-1521308840.85-113836180865947/install_composer.sh: not found\r\n", "stdout_lines": ["/bin/sh: 1: /home/vagrant/.ansible/tmp/ansible-tmp-1521308840.85-113836180865947/install_composer.sh: not found"]}
to retry, use: --limit @/mnt/c/Users/Gary/Development/ansible/playbook.retry
Been searching everywhere, but I can't seem to get it to run. Note that .ansible/tmp directory IS being written to. Not sure why it would not include the sh file
Ansible 2.4.3, Vagrant 2.0.3.
UPDATE: Windows strikes again. I attempted to run the script manually in vagrant command line and got the error:
/bin/bash^M: bad interpreter. Apparently this can happen when you write shell files on Windows (new one to me)
I recreated the install_composer file in vim instead of the ide and worked just fine.
credit to this guy:
https://stackoverflow.com/q...
Hey gstanto ,
Glad you got it working! And thanks for sharing this info for our Windows friends ;) Btw, the answer seems pretty popular on GitHub, so I bet many users get this error.
Cheers!
Ran into the same problem.
I'd add that after converting the file to LF from CRLF (there's a button for that at the bottom right in phpStorm) you can create a
.gitattributesfile to tell git to always store files inansible/scripts/using LF, otherwise you'll have this problem every time you check out your repository. See https://stackoverflow.com/a/63736688/1419007Hey Aksfjaw,
Thank you for sharing your alternative solution! Sounds valid to me
Cheers!
Hi,
How do we add an user to an ubuntu server with Ansible, other than root user, which can run composer without issues? Composer warns about running "composer install" command as root.
My server is an ubuntu server with root as default and no other users created. The login is made through SSH as root.
L.E.: I fixed it by creating a new user on ubuntu server manually then modified the Ansible playbook to use that specific user.
Hey Liviu,
Good workaround, well done! In case you still want to automate this, let's see what options you have.
Remember, if you don't know a specific Ansible command that you can use for doing things you want - you can always use "command" or "shell" to execute *whatever* console commands you want manually. So, just google how to create users in Ubuntu servers with a CLI command and use it :)
Though, if you're interested in creating users with Ansible - Ansible really has a specific command for this called "user" :) See the docs about it: https://docs.ansible.com/an... - you can do a lot of things with it, look at examples to start.
I hope this helps!
Cheers!
"Houston: no signs of life"
Start the conversation!