I have multiple versions of PHP (5.6 and 7.2) installed on my CentOS 7 server.

Googling CentOS 7 Composer installation seems to have the same guide, just under a different blog with these steps:

$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer
$ chmod +x /usr/local/bin/composer
$ composer -V    
Composer version 1.5.2 2017-09-11 16:59:25

However, this threw an error straight away. So I changed this command:

$ curl -sS https://getcomposer.org/installer | php


$ curl -sS https://getcomposer.org/installer | php72

This now downloaded the file, however when I tried using composer -V (after the other steps) it throws this error:

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

So I vim'd into /usr/local/bin/composer to see the line right at the top:

#!/usr/bin/env php

I changed that to

#!/usr/bin/env php72

but doing composer -V now shows:

PHP Fatal error:  Uncaught PharException: phar "/usr/local/bin/composer" has a broken signature in /usr/local/bin/composer:23
Stack trace:
#0 /usr/local/bin/composer(23): Phar::mapPhar('composer.phar')
#1 {main}
  thrown in /usr/local/bin/composer on line 23

I tried the same with php56 to the same result.

How do I go about installing composer correctly on a CentOS 7 server running multiple versions of PHP?

Sidenote: lemme know if this is better for say ... superuser

2 Answers 2


It all depends on the version of php you would like to use. Could you please show us the error you get when you try to install composer with php56 ?

Anyways "php" is just a symlink to the real php binary, wich in your case seems to be pointing to php 56, to make sure of that do a ls -l on the symlink, that you can locate by typing

whereis php

So if you want the full chain to be php72, replace that symlink with a new one that will point to the php72 binary. Or perhaps you can use an alias :

alias php="/path/to/php72"
  • 1
    the exact same^^ however I did find a solution after making the question! and it pretty much is the alias fix you have above^^
    – treyBake
    Apr 10, 2019 at 9:09

My overall solution was to do this:

  1. Create an alias in ~/.bashrc: alias php="php72"
  2. Then install composer with above steps without any amedments
  3. Then go back into ~/.bashrc to add a new alias: alias composer_72="php /usr/local/bin/composer"

Now I have composer working on PHP7.2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.