Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AliMalik's avatar

Run composer commands with different php versions

I have two php versions installed on my system php 5.3 and php 5.6 When running commands in cmd for version check i got this :

php -v
PHP 5.3.28 (cli) (built: Dec 10 2013 22:27:36)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies

and for php 5.6

php56 -v
PHP 5.6.17 (cli) (built: Jan  6 2016 13:28:21)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies

I have path setup for both of these in my environment. Now while running composer create-project i get error because composer points to php 5.3 and laravel requires php >= 5.5

composer create-project laravel/laravel BlogSys
Installing laravel/laravel (v5.0.22)
  - Installing laravel/laravel (v5.0.22)
    Loading from cache

Created project in BlogSys
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for jeremeamia/superclosure 2.1.0 -> satisfiable by jeremeamia/SuperClosure[2.1.0].
    - jeremeamia/SuperClosure 2.1.0 requires php >=5.4 -> your PHP version (5.3.28) does not satisfy that requirement.
  Problem 2
    - Installation request for laravel/framework v5.0.16 -> satisfiable by laravel/framework[v5.0.16].
    - laravel/framework v5.0.16 requires php >=5.4.0 -> your PHP version (5.3.28) does not satisfy that requirement.
  Problem 3
    - Installation request for league/flysystem 1.0.2 -> satisfiable by league/flysystem[1.0.2].
    - league/flysystem 1.0.2 requires php >=5.4.0 -> your PHP version (5.3.28) does not satisfy that requirement.

When i want to run this composer command appending php or (php56) before composer i got this error

 php composer create-project laravel/laravel BlogSys
Could not open input file: composer

How can i impose composer to execute its command using specific version of php?

0 likes
5 replies
AliMalik's avatar

@helwieahmad Thanks for the link. But what I comprehended is this that it'll simply force Laravel to install even if it doesn't meet the requirements of local machine.

--ignore-platform-reqs: ignore php, hhvm, lib-* and ext-* requirements and force the installation even if the local machine does not fulfill these. See also the platform config option.

AnthonyC's avatar

Know this question is a bit old... but if you pull down composer into your app root:

https://getcomposer.org/download/

Instead of relying on global composer, then you can run:

php56 composer.phar {your command}

or I believe newer homstead versions would be like:

php7.1 composer.phar {your command}
Flipmedia's avatar

This might help some... composer is likely to be using /usr/bin/php, consider the following:-

$ which php
/usr/bin/php

$ /usr/bin/php -v
PHP 7.1.33

$ php -v
PHP 7.2.24

$ type -a php
php is aliased to '/usr/bin/php7.2'
php is /usr/bin/php

$ which composer
/usr/local/bin/composer

As you can see our hosting has an alias to ensure the configured version of php (for webserver) is used on command line. But composer is configured to use /usr/bin/php.

The following is a workaround for the above circumstance.

Update .bash_aliases file

alias php="/usr/bin/php7.2"
alias composer="/usr/bin/php7.2 /usr/local/bin/composer"

Once logged out of terminal and logged back in...

$ type -a composer
composer is aliased to '/usr/bin/php7.2 /usr/local/bin/composer'
composer is /usr/local/bin/composer

composer is now using the correct php version.

8 likes
realtebo's avatar

sudo update-alternatives --set php /usr/bin/php7.2

Please or to participate in this conversation.