Fatal Error: composer.lock was created for PHP version 7.4 or higher but the current PHP version is 7.3.11

后端 未结 14 2202
遇见更好的自我
遇见更好的自我 2020-12-18 20:31

I want to create a Symfony CRUD application. These are the steps I did:

  • Downloaded and installed XAMPP from here with PHP 7.3.11 https://www.apachefriends.org/
相关标签:
14条回答
  • 2020-12-18 21:22

    This is thankfully quite easy to fix. You can tell your composer.json to install vendor libraries based on a specific version of PHP.

    For instance we have a project currently in migration from PHP5 to PHP7. We cant install the PHP7 only versions of the libraries, so we add this to your composer.json:

      "config": {
        "platform": {
          "php": "5.3.29"
        }
      },
    

    Now you should be able to install. Delete your composer.lock, then run composer install!

    Here's the relevant documentation:

    https://getcomposer.org/doc/06-config.md#platform

    0 讨论(0)
  • 2020-12-18 21:24

    I had the same and could fix it by deleting an export path with php 7.2 in my zshrc.

    0 讨论(0)
  • 2020-12-18 21:25

    this can easily happen if you have two different versions of php on your local machine. To get around this find the version of php in console that matches what your local server is running.

    rm composer.lock
    /usr/bin/php /usr/local/bin/composer install
    

    Composer will then recreate the lock file with the proper version of php.

    0 讨论(0)
  • 2020-12-18 21:26

    You should run composer dump-autoload

    0 讨论(0)
  • 2020-12-18 21:26

    I solved this by running

    $ symfony local:php:refresh

    from the project folder, because the output from running $ php --version gave me PHP 7.4.1 (cli) while $ symfony php --version gave me PHP 7.3.13-1+ubuntu16.04.1+deb.sury.org+1.

    After the refresh they showed the same versions.

    Edit: This required the use of the symfony-binary

    0 讨论(0)
  • 2020-12-18 21:26

    the php folder that the composer installed in and the the apache server such as xampp, wampp, lampp version are should be the similar.

    for exmaple if the version of php that composer is installed with is 7.4 or higher, the apache server version such as xampp, wampp, lampp also should be 7.4 or higher

    0 讨论(0)
提交回复
热议问题