1

I installed Docker and Nitro and successfully used nitro create <folder-name>, and ended up with the 'Welcome to Craft CMS!' message.

I cded into the new folder and invoked ./craft setup, which along the way has reported 'success!' at testing database credentials.

After saying yes to installing on the command line and creating an admin user account, I've received:

*** installed Craft successfully (time: 12.240s)

Generating project config files from the loaded project config ... done

I can see my new local dev instance running in Docker.app, but when I go to the site in a browser I get 503 – Service Unavailable.

If I go to {hostname}/admin I get the browser prompt to Install Craft. If I try and fill that out I get PDO exception: SQLSTATE[HY000] [2002] Connection refused.

The potential ease of use of Nitro looks really promising so it's frustrating to be so close!

What could I be missing?


Update 1

I have the following in my .env:

DB_DRIVER=mysql
DB_SERVER=127.0.0.1
DB_PORT=3306
DB_DATABASE=<dbname>
DB_USER=nitro
DB_PASSWORD=nitro
DB_SCHEMA=
DB_TABLE_PREFIX=

where <dbname> is the DB name I was asked to define (during nitro create I think) and which it said it could connect to.

Under 'Databases' nitro context reports:

Databases:
  engine:        mysql 5.6      hostname: mysql-5.6-3306.database.nitro
  username:      nitro  password: nitro
  port:  3306

Update 2

To start from scratch, I junked my nitro instance in Docker and uninstalled nitro, and then reinstalled it, and went through nitro create again, and…

ended up in basically the same place.

I've tried my custom database name as the value of DB_DATABASE and the default nitro database name, and it makes no difference.

5
  • Did you edit your .env file or have Nitro do it for you? Your DB_* values need to reference the details you get for the relevant database engine running nitro context.
    – Matt Stein
    Mar 16 at 14:45
  • Thanks Matt. Re the .env I did a combination of both I think. I have updated my question above with the current state. Mar 16 at 14:57
  • 2
    Nitro should have updated .env so that DB_SERVER=mysql-5.6-3306.database.nitro in this case, not 127.0.0.1.
    – Matt Stein
    Mar 16 at 17:16
  • Ah, of course! So obvious now you point it out. That has worked thanks. Do you want to post it as an answer so I can vote for it? Mar 16 at 17:24
  • Answered—thank you! :)
    – Matt Stein
    Mar 16 at 20:11
3

After cheating via discussion in the comments, I’m certain that your DB_SERVER is incorrectly set to 127.0.0.1 when it should in fact be mysql-5.6-3306.database.nitro.

In a perfect world this would have been set for you when Nitro edited .env, but in a pandemic-ravaged dystopia your next best option is to use whatever nitro context indicates.

2
  • FWIW the Craft starter project was tragically overwriting the .env Nitro likely set up for you with nitro create, which we’ve fixed. Should be smoother sailing going forward!
    – Matt Stein
    Mar 16 at 22:00
  • Thanks for your help Matt :) Mar 17 at 11:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.