39

On CentOS 7, I installed PHP 7.1.

Then I installed composer with:

cd /tmp
curl -sS https://getcomposer.org/installer | php71     --> used php71 instead of php, php didn't work
mv composer.phar /usr/local/bin/composer

Then, when using composer, I get:

/usr/bin/env: php: No such file or directory

When using sudo composer, I get:

sudo: composer: command not found
user3489502
  • 3,451
  • 9
  • 38
  • 66

5 Answers5

56

As @alexhowansky suggested in a comment, I ran the following command:

sudo ln -s /usr/bin/php71 /usr/bin/php

Now the composer command works.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
user3489502
  • 3,451
  • 9
  • 38
  • 66
  • This help. Note: in Monterey, you need to alter the command to: sudo ls -s /usr/local/bin/php, whereas can be /Applications/AMPPS/apps/php74/bin/php if you have AMPPS, etc... – victor_luu Sep 30 '22 at 07:40
  • sudo ln -s /usr/local/bin/php Fixed the command mentioned in the above comment. – Gihan De Silva May 09 '23 at 06:05
  • This is still work for me, i install composer from their website and use it globally with this command 'sudo mv composer.phar /usr/local/bin/composer' but it didnt work, after that i use this command 'sudo ln -s /opt/lampp/bin/php /usr/bin/php' and its work, i use lampp btw, ThankYou – Coldalpha May 28 '23 at 08:01
11

You need to add /usr/local/bin to your PATH variable. The easiest way is to throw it in your profile or bash_profile located at either:

  • ~/.profile
  • ~/.bash_profile

You would add the following to one of those files:

export PATH="$PATH:/usr/local/bin/"

For more details, see: https://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path

If you are logged in when you add it, you can force Linux to read the file again and update the path (once the changes are made) by using source from the bash prompt:

source ~/.bash_profile

As for the php7 vs. php issue, as Alex suggested, you can make a symlink so it works kinda like an alias.

Jeremy Harris
  • 24,318
  • 13
  • 79
  • 133
  • One thing I'll add here: your mileage may vary per specific use case. When I added `export PATH="$PATH:/usr/local/bin/"` to my .bash_aliases, running `which php` returned `/usr/local/bin//php`. So, I modified it to `export PATH="$PATH:/usr/local/bin"`, which works fine. – karolus Oct 04 '18 at 13:30
3

This worked for me [Centos 7 with php 7.1] :
yum install php71w-cli

Ari
  • 326
  • 2
  • 5
2

You need to install the cli package.

yum install php71u-cli is what I needed to do for IUS php.

fred
  • 1,146
  • 11
  • 16
-1

This problem arises when you have composer installed locally.

To make it globally executable,run the below command in terminal,

sudo mv composer.phar /usr/bin/composer
Codemaker2015
  • 12,190
  • 6
  • 97
  • 81