I want to generate a Symfony application which can be compatible with PHP version up to 7.4.22.
On my local machine, PHP version is 8.0.2 but on the hosting is 7.4.22.
Symfony application is generated from local machine using standard composer command
composer create-project symfony/website-skeleton my_project_name
I look over create-project
arguments to see if I could add some constrains but none seems to be useful.(or didn’t figure out)
If try to upload to host the project I get this when trying to install it:
Your Composer dependencies require a PHP version ">= 8.0.0". You are running 7.4.22.
Need just a default empty project to check something on hosting.
I do not want to alter local PHP and doing the same thing on hosting could be troublesome.
2
Answers
You cannot add a "dependency constraint" to
create-project
.E.g. Something like an imaginary
create-project symfony/skeleton --dep php: "^7"
.What you could do is:
create-project
config.platform
key to yourcomposer.json
adjusted to your server’s version (Docs.)composer update
Either some packages will be downgraded if needed, or you’ll get a message telling you that the new, target version is incompatible.
E.g. after doing a
create-project symfony/skeleton
and changingconfig.platform.php
to7.2
, on executingcomposer update
I get:Running
composer create-project symfony/website-skeleton my_project_name
in an example project using PHP 8 installspsr/cache
in v2 andpsr/link
in v1.1.1. These package versions require PHP 8, and they will not work using any older version of PHP.To avoid this, just don’t run
composer create-project
with any later version than the one you want to use on your production system (as usually, running it with a lower PHP version than on production yields a set of packages that is compatible with the production system, while the chance is lower the other way around).Otherwise, check whether there are such package versions using
composer why-not php 7.4
before deploying and downgrade them