Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing Composer on EC2 Linux Command Not Found

I run the following commands to install the Composer:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === 'aa96f26c2b67226a324c27919f1eb05f21c248b987e6195cad9690d5c1ff713d53020a02ac8c217dbf90a7eacc9d141d') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php --install-dir=/usr/local/bin
php -r "unlink('composer-setup.php');"

Afterwards, when I run composer, I see that it is working. However, whenever I run sudo composer, I always receive

Command Not Found.

The output ofthe echo $PATH is:

/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin

What can I do to enable composer under sudo?

like image 619
MadPhysicist Avatar asked Dec 12 '16 19:12

MadPhysicist


2 Answers

If you can run composer "alone" then you should have composer installed in /usr/local/bin/composer so you can just link it to /usr/bin/composer with

sudo ln -s /usr/local/bin/composer /usr/bin/composer

and then run

sudo composer install
like image 25
Lucio Vicentini Avatar answered Sep 29 '22 07:09

Lucio Vicentini


First you need to SSH into your EC2 instance

ssh -i ~/.ssh/<your_group_security>.pem ec2-user@<ec2-public-ip>

Run below command on your EC2 instance

$ cd ~
$ sudo curl -sS https://getcomposer.org/installer | sudo php
$ sudo mv composer.phar /usr/local/bin/composer
$ sudo ln -s /usr/local/bin/composer /usr/bin/composer

Then you can run verify composer installation

$ sudo composer install

like image 187
NISHANK KUMAR Avatar answered Sep 29 '22 08:09

NISHANK KUMAR