简体   繁体   English

Laravel 5.6 + cPanel + Composer错误:即使安装了7.2,也使用了错误的PHP

[英]Laravel 5.6 + cPanel + Composer Error: Using wrong PHP Even though 7.2 is installed

I am trying to install Laravel 5.6 on a cPanel sandbox and I am getting strange behavior where composer is trying to use PHP 5.6 even though 7.2 is setup. 我正在尝试在cPanel沙箱上安装Laravel 5.6,并且在安装了7.2的情况下,作曲家尝试使用PHP 5.6时,我得到了奇怪的行为。 Here are the details: 详细信息如下:

# composer --version
Composer version 1.1.1 2016-05-17 12:25:44

The command which php returns nothing. which php命令什么也不返回。 But when I do alias I get the following: 但是当我做alias我得到以下信息:

alias php='/usr/local/bin/ea-php72'

And if I run php -v I see 如果我运行php -v我会看到

# php -v
PHP 7.2.4 (cli) (built: Apr  4 2018 00:56:46) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

I am going to assume that it's working. 我将假设它正在工作。 As you can tell, I have very little experience running Laravel on cPanel, but I digress. 如您所知,我在cPanel上运行Laravel的经验很少,但是我离题了。

Here's the error: 这是错误:

# composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - This package requires php ^7.1.3 but your PHP version (5.6.35) does not satisfy that requirement.
  Problem 2
    - laravel/framework v5.6.9 requires php ^7.1.3 -> your PHP version (5.6.35) does not satisfy that requirement.
    - laravel/framework v5.6.8 requires php ^7.1.3 -> your PHP version (5.6.35) does not satisfy that requirement.
    - laravel/framework v5.6.7 requires php ^7.1.3 -> your PHP version (5.6.35) does not satisfy that requirement.
    - laravel/framework v5.6.6 requires php ^7.1.3 -> your PHP version (5.6.35) does not satisfy that requirement.
    - laravel/framework v5.6.5 requires php ^7.1.3 -> your PHP version (5.6.35) does not satisfy that requirement.
    - laravel/framework v5.6.4 requires php ^7.1.3 -> your PHP version (5.6.35) does not satisfy that requirement.
    - laravel/framework v5.6.3 requires php ^7.1.3 -> your PHP version (5.6.35) does not satisfy that requirement.
    - laravel/framework v5.6.2 requires php ^7.1.3 -> your PHP version (5.6.35) does not satisfy that requirement.
    - laravel/framework v5.6.15 requires php ^7.1.3 -> your PHP version (5.6.35) does not satisfy that requirement.
    - laravel/framework v5.6.14 requires php ^7.1.3 -> your PHP version (5.6.35) does not satisfy that requirement.
    - laravel/framework v5.6.13 requires php ^7.1.3 -> your PHP version (5.6.35) does not satisfy that requirement.
    - laravel/framework v5.6.12 requires php ^7.1.3 -> your PHP version (5.6.35) does not satisfy that requirement.
    - laravel/framework v5.6.11 requires php ^7.1.3 -> your PHP version (5.6.35) does not satisfy that requirement.
    - laravel/framework v5.6.10 requires php ^7.1.3 -> your PHP version (5.6.35) does not satisfy that requirement.
    - laravel/framework v5.6.1 requires php ^7.1.3 -> your PHP version (5.6.35) does not satisfy that requirement.
    - laravel/framework v5.6.0 requires php ^7.1.3 -> your PHP version (5.6.35) does not satisfy that requirement.
    - laravel/framework 5.6.x-dev requires php ^7.1.3 -> your PHP version (5.6.35) does not satisfy that requirement.
    - laravel/framework v5.6.15 requires php ^7.1.3 -> your PHP version (5.6.35) does not satisfy that requirement.
    - Installation request for laravel/framework 5.6.* -> satisfiable by laravel/framework[5.6.x-dev, v5.6.0, v5.6.1, v5.6.10, v5.6.11, v5.6.12, v5.6.13, v5.6.14, v5.6.15, v5.6.2, v5.6.3, v5.6.4, v5.6.5, v5.6.6, v5.6.7, v5.6.8, v5.6.9].

Now, I did find a thread that says to add a platform to the composer.json: 现在,我确实找到了一个线程,该线程说要向composer.json添加平台:

"platform": {
    "php": "7.1.3"
}

This did let me install my vendor packages, but it's obviously not meant to be a solution since you are simply faking the platform (I think). 这确实让我可以安装我的供应商软件包,但这显然不是要作为解决方案,因为您只是在伪造该平台(我认为)。 When it comes time to really use php7 I get the following error on null coalescing operator, which is a php 7 feature, and so it's still trying to use php5.6. 当真正使用php7时,我在null合并运算符上收到以下错误,这是php 7的功能,因此它仍在尝试使用php5.6。

> Illuminate\Foundation\ComposerScripts::postAutoloadDump

Parse error: syntax error, unexpected '?' in /public_html/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php on line 233

Additional notes: 补充笔记:

phpinfo() - PHP Version 7.2.4
php.ini - /opt/cpanel/ea-php72/root/etc
core PHP Version 7.2.4

# /usr/bin/env php -v
ea-php-cli Copyright 2017 cPanel, Inc.
PHP 5.6.35 (cli) (built: Apr  4 2018 00:55:31)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

My required composer.json is as follows: 我需要的composer.json如下:

"require": {
    "php": "^7.1.3",
    "edujugon/laravel-google-ads": "^1.4",
    "fideloper/proxy": "^4.0",
    "laravel/framework": "5.6.*",
    "laravel/tinker": "^1.0"
}

Any ideas on how I can fix this? 关于如何解决此问题的任何想法?

what is your php version mentioned in composer.json file ? 在composer.json文件中提到的php版本是什么? make sure it looks like this 确保它看起来像这样

 "require": {
        "php": "^7.1.3",
        "darkaonline/l5-swagger": "5.6.*",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "5.6.*",
        "laravel/tinker": "^1.0"
    },

or you can try one of these solutions 1) try reinstalling php on your server 2) you can ignore dependencies like this composer install --ignore-platform-req s 或者您可以尝试以下解决方案之一:1)尝试在服务器上重新安装php 2)您可以忽略诸如composer install --ignore-platform-req这样的依赖项

As it turns out the solution ended up being that we needed to change the default server wide php version to 7.2, and so we did. 事实证明,解决方案最终是我们需要将默认的服务器范围php版本更改为7.2,所以我们做到了。 Since we have a shared hosting setup we set all previous existing sites to default locally to 5.6 and going forward any Laravel installation will be set to 7.2. 由于我们拥有共享的托管设置,因此我们将所有以前的现有站点在本地默认设置为5.6,然后将所有Laravel安装设置为7.2。 Not sure if this is the best solution but it certainly did the trick. 不知道这是否是最好的解决方案,但确实可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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