phpsymfonycomposer-php

How to force creating a new Symfony application for a specific PHP version?


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.


Solution

  • 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