29

I just wondering how composer check which php to use when check for requirements. I use MacOS and in terminal type:

composer require phpunit/phpunit

the result is something like:

Problem 1
- phpunit/phpunit 5.0.4 requires php >=5.6 -> your PHP version (5.5.27) or "config.platform.php" value does not satisfy that requirement....

When I check php version:

php -v

The result is:

PHP 5.6.10 (cli) (built: Jun 12 2015 14:08:56) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans

Which is:

which php

php: aliased to /Applications/MAMP/bin/php/php5.6.10/bin/php

Can someone explain this. Thanks in advance!

3
  • What does phpinfo() says about your php version ? Commented Oct 11, 2015 at 11:04
  • 5.6.10 - I use Mamp with 5.6.10 default version. Commented Oct 11, 2015 at 11:06
  • 2
    I'd say you simply have more than one PHP version installed. Commented Oct 11, 2015 at 11:43

4 Answers 4

69

Composer can tell you what version of PHP it's running on, if you specify debug verbosity -vvv.

I like to run it with the about command, since the output is relatively short.

composer -vvv about

Example output:

... Running 1.8.5 (2019-04-09 17:46:47) with PHP 7.3.5 on Darwin / 18.6.0 ...

Edit: This has gotten more interest than I expected, so here's a version with cleaner output:

composer -vvv about 2>&1 | grep "PHP"
Sign up to request clarification or add additional context in comments.

3 Comments

on Centos7 php -v and phpver all indicate 7.4 but installing Craft, Composer is running with php5. Any ideas why? I'm guessing there's a composer environment variable set somewhere.
@samerivertwice: What does "/usr/bin/env php -v" show?
my man! (not assuming gender, its just an expression :P)
4

( sharing this here because I was looking for it an landed here but nothing satisfied me so I will share for those who land here for the same reason: )

With the following command you can check which composer packages depend on a specific php version:

composer depends php | grep 8.1

will output something like:

symfony/console                    v6.1.4  requires php (>=8.1)                  
symfony/css-selector               v6.1.3  requires php (>=8.1)                  
symfony/deprecation-contracts      v3.1.1  requires php (>=8.1)                  
symfony/error-handler              v6.1.3  requires php (>=8.1)                  
symfony/event-dispatcher           v6.1.0  requires php (>=8.1)                  
symfony/event-dispatcher-contracts v3.1.1  requires php (>=8.1)                  
symfony/finder                     v6.1.3  requires php (>=8.1)                  
symfony/http-foundation            v6.1.4  requires php (>=8.1)                  
symfony/http-kernel                v6.1.4  requires php (>=8.1)                  
symfony/mailer                     v6.1.4  requires php (>=8.1)                  
symfony/mime                       v6.1.4  requires php (>=8.1)                  
symfony/process                    v6.1.3  requires php (>=8.1)                  
symfony/routing                    v6.1.3  requires php (>=8.1)                  
symfony/service-contracts          v3.1.1  requires php (>=8.1)                  
symfony/string                     v6.1.4  requires php (>=8.1)                  
symfony/translation                v6.1.4  requires php (>=8.1)                  
symfony/translation-contracts      v3.1.1  requires php (>=8.1)                  
symfony/var-dumper                 v6.1.3  requires php (>=8.1)

Comments

3

On MacOs X the default installation of php resides in /usr/bin. If you upgrade your php it will most likely be installed somewhere else (like /usr/local/php5), or if you use MAMP or something else it will be elsewhere. Just make sure that the first occurrence of php when traversing your PATH is the same as the version your webserver is using. (like have /usr/local/php5/bin before /usr/bin in your PATH). That will solve your problem.

1 Comment

How do you configure your path? Which file do you have to access ?
3

If you used a package install method, such as apt-get on Ubuntu, chances are that the executable will include a "shebang" pointing to the specific php that should be used to run that specific composer file.

When using the command composer the cli will first resolve which binary to use. By running which composer you can find what binary that is.

$ which composer
/usr/bin/composer

Once you know that, you can open the file, for instance using vim: vim /usr/bin/composer (generally it takes super user access to modify binaries so you shouldn't be able to mess composer up doing that).

On the first line of the composer binary should be a shebang, possibly looking like #!/usr/bin/php that would instruct the composer executable on how it should run.

You can then call that php binary directly to verify its version:

/usr/bin/php -v

1 Comment

Hello, i have been getting some issues regarding the version of PHP, I couldn't use a package because the version was different, is there a way to change the version using this location or better yet, how to tell composer to use the version from another place? For example the one where 7.4 is installed. Thanks!! Edit: Im using Laravel 8

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.