Setting up Craft CMS 3 on Nanobox
Here @ Vouchertoday.uk we use a super swanky CMS to host all our brilliant coupon codes and vouchers — it’s called CraftCMS. If you haven’t heard of Craft CMS I’d go check it out, it’s like the daddy of Wordpress. We’ve used Craft to build numerous sites, you can pull it, tear it and play with it so to speak. In this tutorial, we’re going to set you up on Nanobox (an epic SaaS solution for dev-ops) which makes handling CraftCMS oh so much easier, there are a few caveats but we’ll make sure we mention them as we go.
You should have a Nanobox account (which you can register here)
Medium amount of time
Some knowledge of PHP (but not essential)
Some knowledge of Liquid Templating (but not essential)
We’re going to set this baby going, let’s dive in.
Create a New Directory
This is where your Craft Install will live, as well as the folder to access your server through Nanobox, the name of your project is usually sufficient. (but it can really be whatever you want.) In the following line, we’re going to create a new directory and
mkdir nanobox-craft3 && cd $_
“What’s in the box?!” you may ask, well, it tells nanobox what kind of server we’re wanting to build out or run. For CraftCMS we want to run it on postgres and have a good stable version of PHP. Below is a great start to a boxfile but there is a lot of possibilities here so do check out the docs.
boxfile.yml file in the root of the folder you’ve just made.
What this code is doing above is telling nanobox what to build, what extensions to add on and what database we’re wanting to run it on. Read more about it here.
Let’s start the local dev.
Before we go ahead and start the server, we should really add an
alias to our server, we don’t want to be accessing 18.104.22.168 every time we want to test our website, we really want to be going to
mysuperproject.local instead. So let’s do just that in our terminal window.
(Be warned, don’t change it to your domain or you want be able to access it via the browser. e.g. if I owned
google.comI would set this to
google.localinstead so I can still access google.com.)
# Add a convenient way to access the app from a browser
nanobox dns add local craft3.local
Let’s see if this beauty wants to purrrr for us. Go ahead and kick the servers off by entering the following command in your terminal.
# Start the dev environment
Let’s Install Craft
Now we’ve got that all running — finally. Let’s install CraftCMS and get our project going! We’re going to use something called
composer which nanobox comes with automatically (sweet!). This is where a caveat comes in — Composer won’t let you create new projects inside directories that aren’t empty, so let’s create a new directory and
cd into that so we can download and install CraftCMS. Enter the following lines into your terminal:
# Move into the /tmp directory
# Install Craft 3 beta
composer create-project craftcms/craft craft -s stable
# Enable the dotglob shell option to interact with hidden files
shopt -s dotglob
# Copy Craft into your project directory
cp -a craft/* /app
# cd back into /app, your project directory
With this done, we now have all the files we need for CraftCMS accessible to us from any code editor such as Atom/Sublime or any others.
Updating our Database Config
Now Craft has downloaded, we just need to tell it where our database lives on Nanobox — it’s as easy as copy and pasting! Open
config/db.php from your project folder with your code editor, and change it to the following:
'driver' => 'pgsql',
'server' => $_ENV['DATA_DB_HOST'],
'user' => $_ENV['DATA_DB_USER'],
'password' => $_ENV['DATA_DB_PASS'],
'database' => 'gonano',
'schema' => 'public',
'tablePrefix' => '',
'port' => 5432
Let’s Start — it’s time.
Roll up, Roll up! It’s time to boot this bad boy up. Enter the following line into your terminal window:
# Start your app
Nanobox is handy, it’ll start apache and everything else for you all with this command. Just to re-iterate how to start a server it’s
nanbox run and then
Remember we made those aliases before? Head to whatever your alias we set up before + /admin like below:
You should see that sweet sweet Craft install screen, follow the instructions and enjoy hacking!