Question

Help with Cloud Init syntax for php -r runcmd

I’d like to include a runcmd that will install Composer on a newly created instance, but the command contains both single and double quotes already when used manually.

This is what I’d like to execute with cloud-init.

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

php composer-setup.php

php -r "unlink('composer-setup.php');"

mv composer.phar /usr/local/bin/composer

I’ve read the cloud init documentation for the runcmd module, but didn’t made much sense about how to implement the above. I hope it’s possible, otherwise I have to bundle the commands into a downloadable bash script for cloud-init to run.

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer