Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling Composer With Specific PHP Version on Homestead

I'm using Homestead to develop a site that will be on a server with PHP 7.0. I want to use .env files, so I ran this Composer command:

composer require vlucas/phpdotenv

When I perused the file, composer.lock, I noticed that a dependency, doctrine/annotations, was requiring PHP 7.1.

I tried adding this to my composer.json file:

"config": {
    "platform": {
        "php": "~7.0"
    }
},

When I run composer update, I get this error:

[UnexpectedValueException]
Invalid version string "~7.0"

I realize that this is because PHP 7.2 is the default version on Homestead. How do I run Composer with PHP 7.0 instead of PHP 7.2?

like image 759
Sonny Avatar asked Feb 15 '18 17:02

Sonny


Video Answer


1 Answers

Executing which composer will give you this output:

/usr/local/bin/composer

The Homestead documentation discusses the multiple PHP versions supported and how to call them from the command line for Artisan. Combining that with the composer path above allows you to do this:

php7.0 /usr/local/bin/composer update
like image 128
Sonny Avatar answered Sep 22 '22 18:09

Sonny