In this document, we’re going to cover creating a Roots WordPress project using best practices. We’re using the full Roots stack including Trellis, Bedrock, and Sage 9.
- If you already have your SSH key added to DigitalOcean, skip to step 4.
- If you already have an SSH key, but it’s not connected to your DigitalOcean, you only need to do steps 3.5-7.
- If you don’t have an SSH key yet in your command line, go to your root directory and create a new SSH key:
- To create RSA key pair- run:
ssh-keygen -t rsa
- Create file path run:
/Users/[username]/.ssh/[key-name]
- When it says “Enter passphrase:”, leave it blank and press enter. (Because Ansible likes to have no passphrase for deploys)
- Enter same passphrase again: (leave blank again, and press enter)
- Catenate the public key run:
cat /Users/[username]/.ssh/[key-name].pub
- When you hit enter, it will show you your public key
- Select,and copy the public key
[cmd+c]
- To create RSA key pair- run:
- Signup/Login to your Digital Ocean account:
- Add a new droplet
- Select pricing plan (I recommend $5/m for most setups)
- Select the Region closest to you (or your target market)
- Select a Ubuntu default image.
- If you already have your SSH key added, just select it.
- If you just created or copied a new SSH key in Steps 2 or 3, click Add\’a0SSH Key and paste the public key. (Note: I like to name it by [key-name] and then specify which machine it exists on, like “MasonMBP”.)
- Add a hostname (I usually version mine 1.0. 1.1, etc)
- Create the droplet\’96 after about a minute your droplet will be spun up.
- Copy the IP address from droplet.
- Back in Terminal:
- Catchall command\’96 run:
sudo nano ~/.ssh/config
(enter password) - Grab\’a0the IP address\’a0from your Digital Ocean droplet:’a0
- Inside of the config file, type\’a0this in (note that my [key-name] is
id_rsa
:’a0
- Exit out, now let’s test our SSH connection from the web user, run:
ssh root@[hostname]
- If it asks you if you’re sure, type: yes
- Now you should be connected to your server via SSH
- You can exit your SSH server by hitting
ctrl + d
- Troubleshooting: If you can’t connect via SSH by running: `ssh web@host` then your public key probably isn’t in ~/.ssh/authorized_keys. You can put it in by running: sudo nano ~/.ssh/authorized_keys, and manually pasting it
- Catchall command\’96 run:
- Install Trellis:
- From your systems root directory, make sure you have all the\’a0requirements‘a0installed on your machine\
- Ansible: easiest to install it via Python. (check v. with
ansible --version
) - VirtualBox install\’a0is pretty straight forward. (check v. with
virtualbox -v
) - Vagrant install is just as straight forward. (check v. with
vagrant -v
) - Vagrant-bindfs is distributed as a Ruby gem. You can install it as any other Vagrant plugin with\’a0
vagrant plugin install vagrant-bindfs
(check v. withvagrant-bindfs -v
) - Go to where you want your site to live, and create a new project folder.\’a0Name it the name of your project\’96 run:
cd ~/sites && mkdir example-project && cd example-project
- Clone Trellis and remove .git folder, run:
git clone --depth=1 git@github.com:roots/trellis.git && rm -rf trellis/.git && cd trellis
Install Trellis: - To install the Vagrant host-manager run:
vagrant plugin install vagrant-hostmanager
- To install the Vagrant host-manager run:
vagrant plugin install vagrant-hostmanager
- Ansible: easiest to install it via Python. (check v. with
- From your systems root directory, make sure you have all the\’a0requirements‘a0installed on your machine\
- Install Bedrock: Back out to your project root folder, clone Bedrock and remove .git folder, run:’a0
cd .. && git clone --depth=1 git@github.com:roots/bedrock.git site && rm -rf site/.git
- Install Sage:
- Install all of Sage’s requirements.
- Use Composer to install Sage-9, run:
cd site/web/app/themes && composer create-project roots/sage sage dev-master
(‘sage’ is interchangeable with whatever you choose to name the theme, but keep in mind that it could mess things up. I usually prefer to keep it just ‘sage’.) - Your file hierarchy should look like this.
- Add Soil, run:
cd .. &&\'a0cd .. &&\'a0cd .. &&\'a0composer require roots/soil 3.7.1
- You might want to check for the latest version here.
- *If the command isn’t found, you’ll need to install composer globally first.
- Configure Sage, at least run:
cd web/app/themes/sage &&\'a0
yarn
- Commit and publish the entire project on Github
- Development:
- Setup Local Development Environment:
- Tip: You can open your project from the Github app by right clicking it, and selecting Open in Atom
- Configure\’a0trellis/group_vars/development/wordpress_sites.yml
- Cofigure\’a0trellis/group_vars/development/vault.yml like
- Note: I added my github username to all/vault.yml and uncommented it.
- To use browsersync:
- Open the project/site/web/app/themes/sage/assets/config.json file in a text editor
- Change the devUrl from \’93http://example.dev\’94 to desired address (i.e. \’93jackalope.dev\’94)
- Also, make sure that the pubic path is updated is you name the theme anything other than ‘sage’.
- Got to your Trellis\’a0directory and run:
vagrant up
- If you ever get a NFS error, check this out.
- Run:
cd .. && cd site/web/app/themes/sage && yarn run start
to make sure it’s working locally.