2

I am totally new to Symfony. After I installed Symfony on my local ddev machine, I get this error

Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.0". You are running 7.4.29. in /var/www/html/symfony/vendor/composer/platform_check.php on line 24

I tried to composer install --ignore-platform-reqs as well, and soon as I run it, I get this error message

Parse error: syntax error, unexpected '|', expecting variable (T_VARIABLE) in /var/www/html/symfony/vendor/psr/log/src/LoggerInterface.php on line 30

My php version is

❯ php -v
PHP 8.1.6 (cli) (built: May 12 2022 23:44:22) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.6, Copyright (c), by Zend Technologies

Compose.json

    "type": "project",
    "license": "proprietary",
    "minimum-stability": "stable",
    "prefer-stable": true,
    "require": {
        "php": ">=7.2.5",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "symfony/console": "*",
        "symfony/dotenv": "*",
        "symfony/flex": "^1.17|^2",
        "symfony/framework-bundle": "*",
        "symfony/runtime": "*",
        "symfony/yaml": "*"
    },
    "require-dev": {
    },
    "config": {

Thanks for help

Update

If you are using docker/ddev, make sure to set the php version inside `config.yml`

Make sure to php version matches the symfony requirements

name: ddev-gitpod
type: drupal9
docroot: web
php_version: "8.1"
webserver_type: nginx-fpm
router_http_port: "80"
router_https_port: "443"
xdebug_enabled: false
additional_hostnames: []
additional_fqdns: []
database:
  type: mariadb
  version: "10.3"
nfs_mount_enabled: false
mutagen_enabled: false
use_dns_when_possible: true
composer_version: ""
web_environment: []
nodejs_version: "16"

balrcoding
  • 111
  • 1
  • 1
  • 9
  • Change `php: ">=7.2.5` to `php: ">=8.1` in your `composer.json` file and update. Your project is probably running on an older 7.4 version you once used and still have installed even if you also have php 8.1 installed in your computer. Check [this](https://stackoverflow.com/a/55905650/17089665) – S. Dre Jun 10 '22 at 10:29
  • How did you install Symfony? Your error message does not make sense. 5.4 only need PHP 7.2.5 yet you somehow have newer software that requires a later version? Have you been editing composer.json? Make a new project and just do clean install using the Symfony CLI. You also seem to have multiple PHP versions on your machine. Do as craigh suggests below to ensure Symfony is using the expected version though that is only part of the puzzle. – Cerad Jun 10 '22 at 13:09

3 Answers3

3

Run this command:

symfony local:php:list

You will get some output listing the various versions of php you have installed on your computer and the one being used by the symfony binary will be highlighted. There will also be instructions on how to control the version used by the binary:

To control the version used in a directory, create a .php-version file that contains the version number (e.g. 7.2 or 7.2.15).

craigh
  • 1,909
  • 1
  • 11
  • 24
2

Edit these 2 things in your composer.json to solve your problem :

 "require": {
        "php": ">=8.1",
}

And

"config": {
        "platform": {
            "php": "8.1.6"
        },
    },
vinceAmstoutz
  • 676
  • 1
  • 4
  • 18
  • Well no. Just no. I know you are trying to help and I promise this will be the last time I comment on one of your posts. You can't just toss stuff out there with no explanation especially if they have no chance of working. The Symfony 5.4.9 composer.json file does not even have a config platform section and changing the main php dependency will not fix anything and indeed will probably break other stuff. The OP probably has multiple PHP versions installed and they have probably manually edited composer.json or did an unconventional install. Perhaps an upgrade. – Cerad Jun 10 '22 at 13:28
  • we'll see, time will tell – vinceAmstoutz Jun 10 '22 at 13:42
  • 1
    Actually this helped. After that I updated composer, and is working – balrcoding Jun 10 '22 at 14:56
  • Thanks you @balrcoding ! And see you Cerad ;) (don't worry I do not hold grudges) – vinceAmstoutz Jun 13 '22 at 07:08
0

I got the exactly the same errors in my Laravel fresh install.

My local server env is Vagrant Ubuntu Nginx. And I have multiple php versions installes in my local. To list:

$ update-alternatives --display php

Check the php cli version:

$ php -v

Then create a info.php file and see the project runing php version <?php echo phpinfo();

There will be 2 different version.

So I changed the project runing php version via Nginx vhost file:

$ sudo vim /etc/nginx/sites-available/your-file-name

Edit the line to your required php version, and that version has to be installed in your server. So in this case, edit the below line in vhost file:

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}

Make sure the php version file path is correct and it is available in your given directory. In my case it is /var/run/php/php8.1-fpm.sock

Sadee
  • 3,010
  • 35
  • 36