Running Craft Commands Against a Craft Nitro Site

It's best to run all `craft` commands through the `nitro` command.

Let’s look back at the project we cre­at­ed in the begin­ning of the course. 

➜ cd ~/training/learnnitro

If I want­ed to check if there are any updates to plu­g­ins or Craft for this project, I would typ­i­cal­ly run 

➜ craft update/info

I like to do this to get an idea what’s avail­able and then plan my next steps. 

But if I run that com­mand, I get a SQL error. Craft checks the data­base when run­ning Craft com­mands and based on what I have set in the .env file for this project, the Craft con­sole com­mand can­not con­nect to the data­base. This because inter­nal to the Dock­er net­work, the MySQL data­base serv­er port is 3306. How­ev­er, exter­nal­ly, it is 3307. I don’t want to change my .env file, so I’ll use the nitro com­mand instead as a way to run com­mands as if I was inside the Dock­er network.

It’s quite sim­ple, real­ly. I just prepend every­thing with the nitro com­mand and then run the craft com­mand as a subcommand.

➜ nitro craft update/info

And that works! 

Because of this, I rec­om­mend run­ning all craft com­mands through the nitro com­mand, just to be sure you don’t run into any issues.

Transcript

Premium

Follow along with the full transcript

Search every word, click any line to jump to that moment, and read along as you watch — a CraftQuest Premium feature.

Sign up for Premium
Instructor
Level
Beginner
Date Published
April 20, 2021