简体   繁体   中英

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?

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

运行命令php70 ,将PHP 7.0设置为PHP的默认系统版本,然后您可以正常运行composer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM