In the previous lesson we discussed why you would want to use a configuration management tool. In this lesson we'll dive into how you automate the customization of new servers using the configuration management tool, Chef. Most of the work in assembling Chef recipes is already done for you. In this lesson you will be able to see how the pieces fit together; however, you will not be required to download each of the individual recipes to get everything working.
Lesson Outcomes
By the end of this lesson you will be able to describe how to add a Chef recipe to your setup, and re-provision Vagrant.
Lesson Summary
In the video, I've already setup Chef recipes, roles, and cookbooks for you. So instead of having to download all the pieces separately, you can just start with the code bundle for this lesson.
The outline provided below, however, includes each of the steps that I went through to prepare the configuration Chef recipes and roles that you're downloading.
Locating and Using Chef Cookbooks
- Locate Chef cookbooks for AMP stack, drush, and Drupal-specific PHP libraries you want pre-loaded.
- Place downloaded cookbooks into a sub-folder in your project directory. For example:
chef-recipes/cookbooks
. - Create a role file to include all of the recipes (from each of the cookbooks) you want to load. This file can be placed into its own roles sub-directory. For example:
chef-recipes/roles/lamp_stack.rb
. - Update the Vagrantfile to include:
- path to cookbooks folder
- path to roles folder
- role(s) to load for this server
- new values for any of the default settings for your recipes
- Provision the machine to enable / set-up / trigger the Chef configuration settings:
$ vagrant provision
The machine is now configured, but does not have Drupal installed. This is on purpose. You probably have a specific Drupal project you're working on.
Customizing Configuration Files to Use Chef Recipes
The role files contain a list of individual recipes, and/or roles that must be run to provision a specific type of server. Generally there are three or four parts to them.
- name
- description
- run list (recipes and roles to add)
- default settings for recipes (optional)
You should investigate the contents of the folder chef-recipes/roles
. There is a detailed README tailored to this learning series, as well as the two roles that were created for this lesson.
The Vagrantfile is well commented, this section includes a quick references of the settings that have been updated in the file.
config.vm.provision :chef_solo do |chef|
# default settings
chef.cookbooks_path = "path_to_cookbooks_folder"
chef.roles_path = "path_to_roles_folder"
# roles and recipes to load
# recipes are generally loaded from within roles
chef.add_role "name_of_role"
chef.add_recipe "name_of_recipe"
# overrides for settings in recipes
chef.json = {
"name_of_recipe" => {
"name_of_setting" => "new_value",
},
}
end
Gotchas
- If you are using these recipes for Drupal 8: the recipe provided for Drush won't work. You'll need to install Drush version 7 or greater (compatibility chart on the Drush project page).
- You will probably want to update Chef with the omnibus plugin for Vagrant if the cookbook you want to add requires a newer version of Chef. On the host machine, install the plugin:
$ vagrant plugin install vagrant-omnibus
. Note: Chef must be updated before it is "run". For this lesson, I opted to use older versions of the cookbooks. 20 hours of my life spent working on upgrades that didn't work. The later scripts provide more flexibility (e.g. install ANY version of Drush, not just 5.8), but they work well enough for our needs. - Apt will only run if the cache is older than a day. The first time the machine is provisioned, this might be a problem. You can force updating the cache with the following setting in Vagrantfile:
chef.json = { "apt" => {"compiletime" => true} }
- If you are running into problems with permissions, refer to the tips in Sharing Files Between Your Guest and Host Machine.
- Windows users will also need to download the following cookbooks, and add them to the directory you have configured for chef.cookbooks_path
- chef-handler
- chef-sugar
- iis
- windows
- xml
- yum
- yum-epel
In previous lessons you learned how to automate the setup of your Vagrant instance. We did not, however, automate the installation of Drupal. This is by design. It gives us the ability to quick create new virtual machines using standard pieces of a LAMP stack before finally installing the specific version of Drupal we want to use. In this lesson you will learn how to install Drupal from the command line using Drush. If you already know how to do this, you should review the Lesson Summary, but you are not required to watch the video as it will be entirely review for you.
Lesson Outcomes
By the end of this lesson you will be able to install Drupal via Drush from within your Vagrant instance.
Lesson Summary
The machine was configured in the previous lesson, but does not have Drupal installed. This is on purpose. You probably have a specific Drupal project you're working on. If you don't, you can use the following instructions to set up a generic instance of Drupal. Note: The Chef recipe we're using supports Drupal 6 and Drupal 7, but not Drupal 8. You'll need to update Drush first if you want to use these instructions to install Drupal 8.
$ vagrant ssh
$ cd /var/www/docroot
$ drush dl drupal
$ cd drupal-XXX
(where XXX is the version number for Drupal you've just downloaded)$ drush si standard --db-url=mysql://root:root@localhost/drupal7 --db-su=root --db-su-pw=root --site-name="Drupal on Vagrant"
(for the lessons, the MySQL database has the username root; and the password root, if you have deviated from these insecure passwords, you will need to update this line to get the site install to work).
Gotchas
This lesson assumes you want to install Drupal 7 using the Chef recipe which was given in the previous lesson. This lesson will not work if you are trying to install Drupal 8 as Drush 6 is not compatible with Drupal 8.
Everyone will use Vagrant a little differently. In this lesson, Emma shares some of her strategies for using Vagrant for her personal developer environment.
Lesson Objectives
By the end of this lesson, you will be able to describe how many Vagrant instances you will use, and why.
Lesson Summary
Emma started with one Vagrant instance per project but found that she switches tasks frequently enough that it was a problem--with only 8G RAM, it's hard to have more than one machine running at a time. Although the shut down + startup procedure only takes about five minutes, but it's still dead time. This is especially true as the shut down/start up time doesn't include pulling a fresh copy of the Git repository and updating the database. Emma recommends: grouping your projects with similar requirements into the same Vagrant instance IF you are limited by hardware resources AND you need to switch tasks frequently. Then, as needed, create new vagrant instances if you can justify the split. For example: if you need two different versions of PHP or two different servers (nginx vs. Apache).
Additional resources
You can typically upgrade your Vagrant and VirtualBox installations without any problems. Occassionally you will run into problems though. If this does happen to you, you will want to remove all Vagrant and VirtualBox software, and then re-install it. Assuming you are using Configuration Management to provision your machines, the only thing you'll lose is your database.
Lesson Summary
You will need to delete files and applications as follows for OSX:
- /Applications/VirtualBox.app
- /Applications/Vagrant.app
- /usr/bin/vagrant
- ~/.vagrant.d
- ~/VirtualBox VMs
Lesson Outcomes
By the end of this lesson, you will be able to remove relevant Vagrant from your system to prepare yourself for a clean installation.
Additional resources
Due to path issues, vagrant ssh
doesn't work on Windows. Although you can update some files to fix this, running PuTTY is slightly more accessible (and has a GUI configuration screen to fill in). In this lesson we cover how to install and use PuTTY to log into your virtual machine. Note: You can use PuTTY from any Windows machine into any Linux server.
Lesson Objectives
By the end of this lesson you will be able to SSH into a remote machine using PuTTY.
Additional resources
What Is jQuery?
FreejQuery makes using Javascript easy. A description of the basic jQuery library, and a brief history of why jQuery exists and how it can be used to simplify development of Javascript for your site.
We introduce code deployment without a terminal using beanstalkapp.com.
Deployment means moving your code from environments such as local to production – with version control, which allows for backups, fixing mistakes, and collaborative environments.
Git is the type of version control used in Drupal, and we'll discuss Git in this lesson.
Additional resources
Introduction to Git
CourseThis is an in-depth course that starts with the basics of version control, establishes some terminology, and a base line workflow, then continues to build on that by going beyond the basics of the various Git commands to make the most out of your tools.
In this lesson we take a look at the methods available to install Git on different operating systems including Windows, Mac OS, and Linux and how to ensure that you're environment is properly setup to start using Git. Then we walk through the installation on Mac OS and finally we'll cover how to invoke Git from the command line and set some basic configuration options like telling Git who we are.
- Know where to go to download the latest verion of Git
- Be able to install Git on your operating system of choice.
- Be able to verify that Git is indeed running in your environment.
- Do some Git configuration with
`git config`, ~/.gitconfig
Additional resources
Download Git Drupal Ladder: Install Git lesson (installs Git on Windows instead of Mac)
This tutorial takes a look at the various resources that are available for getting help with Git including the built-in manual/help pages and examples as well as other documentation that we've found to be useful while learning how to use Git.
There are a lot of different ways to reference a specific commit in Git. This lesson takes a look at the various ways in which you can navigate through the history of a project by cloning the Drupal core repository from Drupal.org and looking at its contents. We'll learn about pointers to each commit, or what Git refers to as a Treeish, and how we can use those as parameters to different commands.
This lesson covers the git diff
command and how to use the command along with a Git Treeish reference to view the differences in a project or a single file between two commits. Or between the current HEAD and the working tree. We'll also take a look at integrating Git with some external diff tools that make reading the output from the git diff
command a bit easier.
In this lesson we're going to quickly jump into the basics of a whole bunch of different git commands and get our repository created, add a couple files, and then view our log.
In this tutorial we'll explain some of the basic tenets of version control systems. We'll define Git terminology like repositories, branches, checkouts, and commits, and provide you with a baseline set of concepts that we can build on throughout the course.
This tutorial dives deeper into the different things you can do with the git add
command. Things like adding multiple files at a time using wildcards and staging and adding only some of the changes you've made in a file and not all of them. We'll also take a look at using a .gitignore file to exclude specific files or even patterns of files from the repository all together.
In this tutorial, we revisit the git commit
command and take a look at some of the additional things you can do with it, like amending a previous commit, and creating commits using shorthand methods. Then we'll look at using the interactive rebase command which will allow us to reword commit message and do other things like squash two commits into a single commit when performing a rebase.
This tutorial takes a look at removing files from your version control system. It's generally not enough to just delete the file in the file system you also need to tell Git that it's been removed and make a commit with that information.
In the real world when you're working on a project with a team of people your code never stands still. It's not at all uncommon to find yourself in a scenario where git merge
or git rebase
simply can't successfully meld two branches without human interaction. For example when both branches contain a commit that modifies the same line of code in a file in different ways. This lesson will take a look at how you can go about resolving these merge conflicts and some of the tools available to help make this process easier by first creating an intentional conflict between two branches and then showing how to resolve it.
In this tutorial, we'll take a look at ways that you can remove changes that you've made to the files in your working tree, how to remove something from the index that you've added but later decided that you're not ready to commit, and some other basic working tree and index house cleaning commands.