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
You can run
composer update
to re-install the vendor library versions that are compatible with your PHP version.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
anddocker rm
them.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.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:
Now you should be able to install. Delete your
composer.lock
, then runcomposer install
!Here’s the relevant documentation:
https://getcomposer.org/doc/06-config.md#platform
I solved this by running
$ symfony local:php:refresh
from the project folder, because the output from running
$ php --version
gave mePHP 7.4.1 (cli)
while$ symfony php --version
gave mePHP 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
You should run
composer dump-autoload
I had the same and could fix it by deleting an export path with php 7.2 in my zshrc.
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
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.
Composer will then recreate the lock file with the proper version of php.
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).I had this problem in the Azure WebApp I solved by setting the CGI to the correct version
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.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
Result: localhost will contact the one who first occupied port 127.0.0.1:80 in the listening queue.
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
andphp7.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.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:
I solved it by updating php-cgi:
Maybe it can help someone like me, the problem was in symfony.lock
Simply change this version to match the one needed by composer (7.3 here)
to whoever ends up coming here for solution this ended up working for me;
in cpanel change php version 7.4 then set it your issue will be solved
https://prnt.sc/20xd1zl