craftcms / nitro

Speedy local dev environment for @craftcms.
https://getnitro.sh
MIT License
178 stars 24 forks source link

Fresh install of Nitro on Mac. nitro create composer dependencies issue #442

Closed rogerdawkins closed 2 years ago

rogerdawkins commented 2 years ago

Description

After a fresh install of Docker and nitro, when I run nitro create I get a Fatal error due to composer dependencies issue. I suspect it is because during the install I selected PHP 7.4. This installation is on a Mac and installed using the bash <(curl -sLS http://installer.getnitro.sh) option.

Steps to reproduce

  1. Install Docker
  2. Install nitro using 'bash <(curl -sLS http://installer.getnitro.sh)'
  3. During install I selected MySQL 5.7 and selected No to both PostgreSQL and Redis
  4. Install of Nitro completed with no errors
  5. Run nitro create nitro-test
  6. During install I selected nitro-test.local as hostname, public_html as web root and PHP 7.4 as PHP version, nitrotest as database name and Yes to update the env file.
  7. The composer packages are all loaded without errors.
  8. Then the script tries to run @php craft setup/welcome at which point I get Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.2". You are running 7.4.24. in /app/vendor/composer/platform_check.php on line 24

I did a search for 8.0.2 in the generated files and there are several that include require php >=8.0.2. The composer.lock file has a require of >=8.0.2 in the symfony/filesystem, symfony/finder, symfony/service-contracts and symfony/string sections.

Additional info

angrybrad commented 2 years ago

That error means that there are dependencies in your composer.json file that require PHP 8.0, but the site you created in Nitro is using PHP 7.4.

If your run nitro edit, then change the site you added to use PHP 8.0, instead of 7.4, save the file, then run nitro apply, that'll solve it for you.

rogerdawkins commented 2 years ago

Thanks Brad, I can understand the error message, but all I've done is run nitro create <project-name> to create a new project. I answered the questions and selected PHP 7.4 as that is what I need to use in this case and I get the error. Is it not possible to use nitro create to start a project that uses PHP 7.4?

angrybrad commented 2 years ago

Is it not possible to use nitro create to start a project that uses PHP 7.4?

You can, but presumably, you ran nitro create on a folder that had an existing composer.json file in it, no? If that's the case, that composer.json file has dependencies that require PHP 8.

rogerdawkins commented 2 years ago

I was just trying to test out Docker and Nitro. They were all fresh installs and the folder for the project did NOT exist.

angrybrad commented 2 years ago

@rogerdawkins got it... in this case, when you run nitro create <project-name>, behind the scenes, it's passing --ignore-platform-reqs in behind the scenes (https://getcomposer.org/doc/03-cli.md), which is causing the PHP version mismatch for the dependency.

A workaround would be to change the site to use PHP (in step 6 of your original post). Alternatively, if you want to use PHP 7.4, then you can nitro add to create a site, nitro ssh into the container, then composer create-project and it should pull in the correct dependencies.

I can give you some more detailed steps if you want to go down that latter route.

rogerdawkins commented 2 years ago

I tried the second option. I was able to nitro add and nitro ssh and then run the composer create-project but not sure what I need to enter for the IP and database credentials.

angrybrad commented 2 years ago

@rogerdawkins database creds are user: nitro pass: nitro. You can get the hostname to use to connect to the database via these instructions: https://craftcms.com/docs/nitro/2.x/usage.html#connecting-to-the-database

rogerdawkins commented 2 years ago

Thanks @angrybrad. Sorry, I should have thought of trying context. All working now.

richard-ell commented 2 years ago

I know this is closed but is there a better workaround to getting this resolved. I am experiencing the same bug and while the process @angrybrad described worked, it was certainly not ideal.

angrybrad commented 2 years ago

@richard-ell this is resolved in the upcoming Nitro 3, but it took some architectural changes that are impractical to backport, ufortunately.

jamiematrix commented 2 years ago

Would an another alternative be to manually download and extract Craft then run nitro add . ? Just got the same error creating a site. The host the site will end up on is running 7.4 so we need to build the site on 7.4 from the start

I went through the steps the same as OP. Ran nitro create site-name, set the hostname, set the web root, selected PHP 7.4, added a db, then updated the .env file. I then noticed the following before the hosts were updated:

Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.2". You are running 7.4.24. in /app/vendor/composer/platform_check.php on line 24

Call Stack:
    0.0001     399048   1. {main}() /app/craft:0
    0.0001     401816   2. require('/app/bootstrap.php') /app/craft:8
    0.0002     402896   3. require_once('/app/vendor/autoload.php') /app/bootstrap.php:11
    0.0003     416960   4. ComposerAutoloaderInit8b38923fcbc98f32318e686c2016e522::getLoader() /app/vendor/autoload.php:7
    0.0003     421576   5. require('/app/vendor/composer/platform_check.php') /app/vendor/composer/autoload_real.php:25
    0.0003     422152   6. trigger_error($message = 'Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.2". You are running 7.4.24.', $error_type = 256) /app/vendor/composer/platform_check.php:24

Script @php craft setup/welcome handling the post-create-project-cmd event returned with error code 255
composer create-project completed 🤘
jskrivanek commented 2 years ago

Same issue here. Does this mean we have to wait for nitro 3 to create new craft projects with nitro?

angrybrad commented 2 years ago

@jamiematrix @jskrivanek this error is specific to nitro create, but all the files are downloaded when the error happens, so another workaround would be to:

alexroper commented 2 years ago

@angrybrad I'm getting this error installing a fresh site with PHP 7.4 or PHP 8.0. Nitro creates the same composer.json file for both sites with the same platform requirements.

...
    "platform": {
      "php": "7.2.5"
    }

It seem like I can resolve this without using platform-check false or --ignore-platform-reqs. The composer.lock file is just out of sync with the composer.json that's created.

These steps work for me:

davorpeic commented 2 years ago

Hi @angrybrad this is still an issue, basically creating new project and selecting php version doesn't make sense at the moment. The above "workaround" does help indeed with getting Craft to work with php 7.4 as selected. But then again trying to install commerce new error comes up.

Problem 1
    - symfony/deprecation-contracts v3.0.0 requires php >=8.0.2 -> your php version (7.4;

Edit: fixed commerce install with --ignore-platform-reqs flag Basically selecting php8 I guess is a way to go? dp

jamiematrix commented 2 years ago

@davorpeic @angrybrad I recently created a new site via Nitro (to play with Craft 4) and even selecting PHP8 from the start created a composer.json file with PHP set to 7.4

johnwbaxter commented 2 years ago

If you're having this issue after using Nitro Create, just delete the vendor folder and the composer.lock file and then run nitro composer install and you're all set.