skip to Main Content

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/de/index.html
  • Navigated to htdocs with the CLI of Windows.
  • Created a symfony project with the command composer create-project symfony/skeleton my_project
  • Opened up my browser (Firefox 70.0.1) and navigate to the URL: localhost/my_project/public/

Here I got the error message:

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

When I check my php version in the CLI with php -v I get the result that I use PHP 7.4.0 (cli).
When I check the php version by clicking the PHPInfo on the dashboard of XAMPP (localhost/dashboard/phpinfo.php), the page shows me the php version 7.3.11.

In the created symfony folder is a file called symfony.lock. There is an entry called
"php": { "version": "7.4" },. Changing this entry did not solve my problem.

Any ideas how to solve this?
And why I cannot install and test the newest symfony with XAMPP?

Thanks a lot guys!

Musa

17

Answers


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

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
  4. 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

    Login or Signup to reply.
  5. 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

    Login or Signup to reply.
  6. You should run composer dump-autoload

    Login or Signup to reply.
  7. I had the same and could fix it by deleting an export path with php 7.2 in my zshrc.

    Login or Signup to reply.
  8. 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

    Login or Signup to reply.
  9. 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.

    Login or Signup to reply.
  10. 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).

    Login or Signup to reply.
  11. I had this problem in the Azure WebApp I solved by setting the CGI to the correct version

       <handlers>
            <remove name="PHP74_via_FastCGI"/>
            <add name="PHP74_via_FastCGI" path="*.php" verb="GET, PUT, POST, DELETE, HEAD, OPTIONS" modules="FastCgiModule"
                 scriptProcessor="D:Program FilesPHPv7.4php-cgi.exe" resourceType="Either" requireAccess="Script"/>
        </handlers>
    
    Login or Signup to reply.
  12. 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.

    Login or Signup to reply.
  13. 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.

    Login or Signup to reply.
  14. My problem was updating php version with sudo update-alternatives --config php didn’t update php-cgi.

    Symfony CLI was still using the old version of php-cgi:

    symfony local:php:list
    ┌─────────┬───────────┬────────────┬─────────┬────────────────┬─────────┬─────────┐
    │ Version │ Directory │  PHP CLI   │ PHP FPM │    PHP CGI     │ Server  │ System? │
    ├─────────┼───────────┼────────────┼─────────┼────────────────┼─────────┼─────────┤
    │ 7.2.34  │ /usr      │ bin/php7.2 │         │                │ PHP CLI │         │
    │ 7.3.23  │ /usr      │ bin/php7.3 │         │ bin/php-cgi7.3 │ PHP CGI │         │
    │ 7.4.11  │ /usr      │ bin/php7.4 │         │ bin/php-cgi7.3 │ PHP CGI │ *       │
    └─────────┴───────────┴────────────┴─────────┴────────────────┴─────────┴─────────┘
    

    I solved it by updating php-cgi:

    sudo apt-get install -y php-cgi
    
    Login or Signup to reply.
  15. Maybe it can help someone like me, the problem was in symfony.lock

    "php": {
        "version": "7.4"
    },
    

    Simply change this version to match the one needed by composer (7.3 here)

    Login or Signup to reply.
  16. to whoever ends up coming here for solution this ended up working for me;

    composer install --ignore-platform-reqs
    
    Login or Signup to reply.
  17. in cpanel change php version 7.4 then set it your issue will be solved
    https://prnt.sc/20xd1zl

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search