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

后端 未结 14 2201
遇见更好的自我
遇见更好的自我 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:09

    This could happen to you if you have 2 different Docker containers running serving the same project. They take turns taking incoming requests. To solve this look for an old zombie Docker containers that uses PHP 7.3.11 and just docker stop and docker rm them.

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

    Under your app folder, create a text file and type in 7.4, then rename the file .php-version with no name, just the extension. And it should work.

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

    You can run composer update to re-install the vendor library versions that are compatible with your PHP version.

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

    It may be caused by the fact you uploaded the file vendor/autoload.php generated on another version of php. This is often the case when using CI/CD to build your PHP app.

    So the best approach would be to exclude this file from your artifacts instead of running composer dump-autoload (which could be the last chance solution).

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

    With 2 PHP versions installed, most likely you forgot to change the etc / hosts file for the test domain. Or you need to edit the DNS.

    //file etc/hosts
    #old host -forgot to delete
    127.0.0.71 demo.symfony.local 
    #new host
    127.0.0.74 demo.symfony.local
    

    I don't know how the XAMPP installer works, (since I usually manually install and configure), but I can assume that most likely when installing a new XAMPP, it changed the paths in the PATH variable (why the console works with version 7.4), and added hosts to the etc / hosts file but did not remove the old hosts (so the site works with old version).

    In my case, PHP versions are separated by IP. If you have 2 PHP versions on one IP, then you will have to stop one of them in order to start another or separate the versions by ports. Otherwise, conflict of interest.
    example

    #httpd.conf -Apache settings (Apache folder for PHP 7.3)
    Listen 127.0.0.1:80
    
    #httpd.conf -Apache settings (Apache folder for PHP 7.4)
    Listen 127.0.0.1:80
    
    # etc/hosts
    127.0.0.1 localhost
    

    Result: localhost will contact the one who first occupied port 127.0.0.1:80 in the listening queue.

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

    Kinda late to the party but in my case (Apache server on Ubuntu 18.04), apart from uninstalling previous versions of PHP and installing PHP v.7.4, I had to delete php7.2.conf and php7.2.load from /etc/apache2/mods-available/ for my Symfony project to register that I am indeed on version 7.4. Apparently these files persisted after I purged all previous PHP versions from my system and installed PHP v.7.4.

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