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?
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With