laravel Composer 不检测 php7,而是使用 5.6。如何设置 CLI 以使用 php7
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48535450/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Composer does not detect php7 instead it uses 5.6. How can I set the CLI to use php7
提问by marlonpd
Here when I execute php -v
, it says it has php7
在这里,当我执行时php -v
,它说它有 php7
but when I try to execute composer update
但是当我尝试执行 composer update
the response it
回应它
Your requirements could not be resolved to an installable set of packages.
Problem 1
- This package requires php >=7.0.0 but your PHP version (5.6.33) does not satisfy that requirement.
How can I fix this? NOTE : I'm not allowed to uninstall previous version of php
我怎样才能解决这个问题?注意:我不允许卸载以前版本的 php
Here is the composer.json
这是 composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=7.0.0",
"fideloper/proxy": "~3.3",
"intervention/image": "^2.4",
"laravel/framework": "5.5.*",
"laravel/passport": "^v1",
"laravel/tinker": "~1.0"
},
"require-dev": {
"filp/whoops": "~2.0",
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~6.0"
},
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\": "app/"
},
"files": [
"app/Helpers/misc.php"
]
},
"autoload-dev": {
"psr-4": {
"Tests\": "tests/"
}
},
"extra": {
"laravel": {
"dont-discover": [
]
}
},
"scripts": {
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate"
],
"post-autoload-dump": [
"Illuminate\Foundation\ComposerScripts::postAutoloadDump",
"@php artisan package:discover"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
}
}
I already tried
我已经试过了
composer update --ignore-platform-reqs
but I still I get another error, which is again related to the above problem.
但我仍然收到另一个错误,这又与上述问题有关。
回答by Veerendra
As stated in the question you already have both the versions of PHP on your system, As Laravel uses the cli version you need to enable 7.X and disable 5.X.
正如问题中所述,您的系统上已经拥有两个版本的 PHP,因为 Laravel 使用您需要启用 7.X 和禁用 5.X 的 cli 版本。
You can achieve that by below commands
您可以通过以下命令实现
$ sudo a2dismod php5.6 // disable the loaded version
$ sudo a2enmod php7.0 // enable the desired version
$ sudo service apache2 restart // restart apache to get it in action
For More information You can install different version of PHP using the below commands
有关更多信息,您可以使用以下命令安装不同版本的 PHP
For Apache
对于阿帕奇
$ sudo apt install php5.6 [PHP 5.6]
$ sudo apt install php7.0 [PHP 7.0]
$ sudo apt install php7.1 [PHP 7.1]
For Ngix
对于 Ngix
$ sudo apt install php5.6-fpm [PHP 5.6]
$ sudo apt install php7.0-fpm [PHP 7.0]
$ sudo apt install php7.1-fpm [PHP 7.1]
To install any PHP modules, simply specify the PHP version and use the auto-completion functionality to view all modules as follows.
要安装任何 PHP 模块,只需指定 PHP 版本并使用自动完成功能查看所有模块,如下所示。
------------ press Tab key for auto-completion ------------
$ sudo apt install php5.6
$ sudo apt install php7.0
$ sudo apt install php7.1
Now you can install most required PHP modules as per your requirements.
现在您可以根据您的要求安装最需要的 PHP 模块。
------------ Install PHP Modules ------------
$ sudo apt install php5.6-cli php5.6-xml php5.6-mysql
$ sudo apt install php7.0-cli php7.0-xml php7.0-mysql
$ sudo apt install php7.1-cli php7.1-xml php7.1-mysql
回答by justice
i had same issue and solved it by changing path under system variables.
我有同样的问题并通过更改系统变量下的路径来解决它。
- right click on my computer and click properties
- click advanced system settings on the left side menu
- make sure the advance tap menu is selected
- click on environment variables (buttom right)
- click on path under system variables panel
- click on edit
- locate php installed path (eg. C:\wamp64\bin\php\php5.x.x)
- click edit and rename to your disired php version (eg. C:\wamp64\bin\php\php7.3.5)
- click ok to save
- 右键单击我的电脑,然后单击属性
- 单击左侧菜单中的高级系统设置
- 确保选择了高级点击菜单
- 单击环境变量(右下角)
- 单击系统变量面板下的路径
- 点击编辑
- 找到php安装路径(例如C:\wamp64\bin\php\php5.xx)
- 单击编辑并重命名为您不想要的 php 版本(例如 C:\wamp64\bin\php\php7.3.5)
- 点击确定保存
回答by Armin
Check where your composer executable is located (using which) and check the first line (shebang). I guess this still points to old php version.
检查您的 composer 可执行文件所在的位置(使用 which)并检查第一行(shebang)。我想这仍然指向旧的 php 版本。
回答by Madhu Nair
Install via this sudo apt install php7.1 php7.1-fpm
and recheck again and post the result.
通过此安装sudo apt install php7.1 php7.1-fpm
并重新检查并发布结果。
回答by Nico Haase
If you want to run composer with a different PHP version, try calling it using php $(which composer) update
. You can exchange the path to the PHP cli now freely
如果您想使用不同的 PHP 版本运行 composer,请尝试使用php $(which composer) update
. 您现在可以自由交换 PHP cli 的路径
回答by Krzysztof Dryja
I use phpbrew
for multi PHP versions. In my case this command fixed the issue with composer
using wrong PHP version:
我phpbrew
用于多个 PHP 版本。就我而言,此命令解决了composer
使用错误 PHP 版本的问题:
phpbrew app get composer