skip to Main Content

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


  1. 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:

    1. first create-project
    2. Add the config.platform key to your composer.json adjusted to your server’s version (Docs.)
    3. Run 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.

    enter image description here

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

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