Reputation: 1786
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.
Upvotes: 0
Views: 2080
Reputation: 3
Another option is to use the --ignore-platform-reqs
flag
composer create-project symfony/skeleton my-project-name --ignore-platform-reqs
However, this failed as the PHP code executed during the setup was not compatible with the version of PHP set in the system path.
So if required, manually run composer from the required PHP executable.
C:/xampp/php83/php.exe C:/ProgramData/ComposerSetup/bin/composer.phar create-project symfony/skeleton my-project-name --ignore-platform-reqs
I added the config.platform setting just to be safe:
"config" : {
"allow-plugins" : {
"php-http/discovery" : true,
"symfony/flex" : true,
"symfony/runtime" : true
},
"bump-after-update" : true,
"sort-packages" : true,
"platform": {"php": ">=8.3"}
},
Upvotes: 0
Reputation: 47329
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 your composer.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 changing config.platform.php
to 7.2
, on executing composer update
I get:
Your requirements could not be resolved to an installable set of packages.
Upvotes: 3
Reputation: 12105
Running composer create-project symfony/website-skeleton my_project_name
in an example project using PHP 8 installs psr/cache
in v2 and psr/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
Upvotes: 3