Create a free account to get access to additional free training videos. Enjoy this free video from CraftQuest! Create a free account to get access to additional free training videos. Join the Community
Local Development with Craft Nitro
Now that we have Nitro installed, we are ready to create our first Craft hosted with Nitro.
Now that we have Nitro installed, we are ready to create our first Craft hosted with Nitro. For this video, we’ll focus on setting up a new site with Nitro. In the next video we’ll look at migrating an existing project.
Nitro is a global command, so we do not install anything inside of our project. That means we can pick where we want to store our project files on our local computer and then initialize a new project there using Nitro.
The command we will use for this example is nitro create
.
I do this in the training
directory in my user directory on my computer. This is where I keep all of the projects I use to create these training videos and write articles. For my actual work where I create projects for myself or for clients, I use the projects
directory in my user directory.
nitro create
The nitro create
command that we will use does two things: it creates a new Craft project (like you would with composer create-project
) and it adds that project to Nitro (like you would do in an existing project with nitro add
— more on that later).
So, find a place on your file system where you want to install a fresh copy of Nitro, and let’s get started.
➜ cd ~/training
With the project directory created, we can now run nitro create
. This command takes one argument, which is the name of the project. Nitro will create the directory for the project based on the name and name the hostname based on the name, too.
➜ nitro create learnnitro
This downloads the Craft application begins the setup process. This an interactive setup process, so we will be asked to confirm or input some settings.
The first one is the hostname. It will default to the name of the directory and then the .nitro local TLD. Hit Enter to accept as it is. Anything in the square brackets is the default input if we just hit Enter and do not specify anything custom.
The website’s webroot will default to web
, which we want to keep since that is the default directory name in a new Craft installation.
The next step is to choose the PHP version. My advice here is to choose the PHP version that is the same as running in production. Let’s choose 7.4.
We do need a database for this project because Craft requires one, so we will choose Y, and we will choose the database engine for MySQL.
In Nitro, I typically name the database after the hostname and project name it’s easy to find the database I need. So we will input learnnitro
as the name of the database.
Now Nitro will update the project .env
file so it has the credentials needs to connect to the database.
At this point, Composer will kick in and download the dependencies for the Craft project. This process is similar to the part where we run composer create-project craftcms/cms
when setting up a new project without Nitro.
Now Nitro spins up the Docker containers and makes sure everything is working as expected.
We will be Wprompted for your admin password so Nitro can update the hosts file on your computer. On macOS, this is located in /etc/hosts
.
That is it! The containers are running!
Our next step is to run craft setup
and get the site configured. For this step, we want to interact with Craft through the container. For that reason, we will prepend nitro
to our craft
commands.
➜ nitro craft setup
Choose the project we create by inputting the number and then follow the prompts to set up Craft.
It will now run the installation process and populate the database with the default data needed to start a new Craft project!
Let’s fire up the browser and see what is there. Go to https://learnnitro.nitro to see the site!
Local Development with Craft Nitro is made up of the following videos: