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
Webinar: Easily Create Maps with Leaflet
Blog postCurious about Leaflet? Join Drupalize.Me Trainer Amber Matz for a live tutorial on how to add Leaflet maps to your Drupal site during this Acquia hosted webinar on May 1, 2014 at 1:00 PM EDT.
Hiding Form Fields in Drupal 8
Blog postIf you have worked with the Field UI in Drupal 7 you will know that you are able to prevent fields from being displayed when viewing entities (e.g. content, users etc).
Dupalize.Me Podcast Episode 40
Blog postEver wonder what it means to host your site in "the cloud"? This week's Drupalize.Me podcast, Drupal in the Cloud, uncovers these mysteries. We discuss: what differentiates cloud providers; what it takes to get Drupal in the cloud; and what the future of cloud computing looks like.
Why Vagrant?
FreeVirtualization allows multiple operating systems to simultaneously share processor resources in a safe and efficient manner. One tool we can use to create a virtual environment is Vagrant. By the end of this video, you will be able to describe the advantages, and disadvantages for creating a local development environment with Vagrant, and you should be able to answer the following questions:
- Do you want to proceed with Vagrant?
- Does it sound like it will solve your problems? [yes | no]
- Do you have the necessary hardware to proceed with the lessons? Or should you stick with WAMP/MAMP?
Note: Another common tool for creating development environments today is Docker, which is becoming very popular with Drupal (and other) developers. Take a look at our Drupal Development with Docker series to learn more.
Additional resources
Note: This video is outdated. The following command:
$ vagrant init precise32 http://files.vagrantup.com/precise32.box
...now has download problems if you try it. Try this instead:
$ vagrant init hashicorp/precise64
(The written instructions below contain this update.)
Before we jump into the automation of creating a new developer environment, we need to get the building blocks we'll be working with. You will need to download and install both Vagrant and VirtualBox.
Lesson Outcomes
By the end of this lesson, you will be able to install Vagrant and VirtualBox on a host platform of OSX, or Windows; and create and destroy a Vagrant instance.
Lesson Summary
- Install VirtualBox
- Install Vagrant
- Create a new directory for your configuration scripts. e.g. Websites, or Work-environments. This folder will not contain the VirtualBox binary files, just the Vagrant configuration scripts.
- From the command line, run the following commands:
$ vagrant init hashicorp/precise64
$ vagrant up
$ vagrant ssh
Note: this command will not work for Windows. You will need to use PuTTY to log into your machine. This is covered in the bonus lesson.
- To return to your host machine, run the command:
$ exit
- To destroy the VM and remove the binary disk image:
$ vagrant destroy
This command must be run from the directory which contains the Vagrantfile for the box you wish to destroy. It will not remove any of your configuration files. To recreate the machine, use the commands in step 4.
Troubleshooting and Gotchas
- The lessons were recorded using Vagrant 1.4.3, and VirtualBox 4.3.6.
- There are some gotchas to be aware of: Linux and Windows may need a reboot because of the kernel drivers being added.
- Sometimes upgrades don't work, and re-installing is your best bet. If you have automatic software updates turned on, and Vagrant stops working for you without an obvious reason, try removing everything and re-install using the instructions in this lesson. Removing Vagrant and VirtualBox are covered in one of the extra lessons.
Additional resources
VirtualBox Downloads
Vagrant Downloads
Note: another common tool for creating development environments today is Docker, which is becoming very popular with Drupal (and other) developers. Take a look at our Drupal Development with Docker series to learn more.
In this lesson you will learn how to install a Web server on your virtual machine. Ultimately we will use a provisioning script to automate this task, but this lesson shows you the virtual machine is just like any other server you might have worked with in the past. Any time you want to add new software, you can always come back to this lesson if you (for some reason) don't want to create a recipe and re-provision your machine. Hopefully, though, by the end of this series you'll see why provisioning is a more robust solution than installing software directly.
Lesson Outcomes
By the end of this lesson, you will be able to log into your virtual machine, and use the command line to install new software.
Lesson Summary
- Navigate to www.vagrantbox.es.
- Locate a base box you would like to use. Ensure you are matching the "provider" to what you have. e.g. VirtualBox for these lessons (not VMware).
- At the command lines, initialize your new server:
$ vagrant init <box name> <box URL>
- box name: ringtail64
- box URL (mind the line wrap): http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box
$ vagrant up
Ensure your server is up and running, and then log in with the command: vagrant ssh. This command must be issued from within the directory which contains the file Vagrantfile.
Install an AMP server using the directions for your base box. We'll use the same technique as is covered in the lesson Installing a Web Server on Ubuntu.
$ sudo apt-get install tasksel
$ sudo tasksel install lamp-server
This will install Apache, MySQL, and PHP.
To confirm the server is running, use the command: pstree
.
Troubleshooting and Gotchas
- OSX can use vagrant ssh; Windows will need to install PuTTY and use ssh vagrant. Using PuTTY is covered in the bonus lesson for this series.
- If you get the error
tasksel: aptitude failed (100)
, run the following commands:$ sudo apt-get update
$ sudo tasksel install lamp-server
(I got this error on a precise32 base box with a Windows 8 host running inside of Parallels on a Mac OSX machine.)
In order to "find" our virtual server in a Web browser, we need to make a map between the two host machine, and your guest server. To do this we will use a technique referred to as port forwarding. This allows any communication from the host machine (your Web browser) to be automatically redirected to the appropriate location on your guest machine (the Web server). Fortunately this is very simple to do. In this lesson we are going to map port 4567 traffic on the host machine, onto the standard Web port, 80, on the server. This means when you access Web traffic at http://localhost:4567, it will be automatically redirected to Apache on your server. It's almost like a sleight of hand magic trick where a rabbit appears in a hat, but way cooler.
Lesson Outcomes
By the end of this lesson you will be able to correctly configure your server's network settings so that Web pages can be viewed in a browser on your host machine.
Lesson Summary
- Edit your Vagrantfile (Vagrant configuration file to set the following properties:
- Configure port forwarding
config.vm.network "forwarded_port", guest: 80, host: 4567
- Reload the vagrant instance.
$ vagrant reload
- Log into the server, confirm Apache is running. (Hint: it's not running.)
$ curl 'http://localhost:80'
- Start Apache.
$ /etc/init.d/apache2 start
- In a Web browser, navigate to:
http://127.0.0.1:4567
(Hopefully) It works!
Gotchas
This can sometimes be the tricky bit, especially if you already have a lot of custom network configuration. If this lesson doesn't work for you, you will need to do an audit of your system to find any software which might be interfering with the connection. We're going to limit ourselves to one VM running at a time (all the same ports). This is mostly because of the hardware limitations I expect you'll have. If your machine is more powerful, great! But we're not covering it in this video series.
What is Drupal (8)?
Blog postWith the release of Drupal 8 approaching, it’s time again to answer and update the age old question: What is Drupal?
Drupalize.Me Podcast Episode 39
Blog postIf you are looking for good community event ideas, or just want to understand some of what goes into planning an event, check out this week's Drupalize.Me podcast on The Story of the TCD'O
Early Bat Gets Twice the Training
Blog postIn fewer than eight weeks DrupalCon will be upon us. Those registering for Breaking Down Component-Based Web Design before May 2nd will also receive a FREE annual membership from Drupalize.Me.
Heartbleed SSL Bug
Blog postAs you may know, a significant vulnerability in the popular OpenSSL cryptographic software library was discovered this week. Unfortunately this software library is used to encrypt most of the Internet, including the servers on which Drupalize.Me resides. But our team took immediate action to patch this bug, and our servers are no longer vulnerable. The same can be said for our payment processing software, which stores your financial information.
Release Day: Wrapping Up Web Services
Blog postThis week, we're wrapping up Joe Shindelar's latest series Building Web Services with Drupal 7. In these last four videos, you will learn how to use Views to build your API, how to create your own services resource in a custom module, and best practices for how to document your API. Next week, Emma Jane Westby guides you through the process of setting up Vagrant as a local development environment in her series Introduction to Vagrant.
All the power of views made available to your API. Really, what else is there to say? In this lesson Joe walks through installation and basic configuration of the services views module which provides the ability to expose views as resources via the services module.
Additional resources
In addition to using views to expose lists of things via our API we can also take advantage of views exposed filters to allow API consumers more control over the data they are receiving in a request. In this lesson Joe looks at accessing views exposed filters via REST requests by adding an exposed filter to both of the perviously created views and then walking through how the configuration of the view changes the behavior of the filter when used via the services API.
In addition to the built in support for core's data and actions the services module also provides a robust framework for exposing the data and actions of our custom modules as an API. In this lesson Joe writes a basic module which creates a custom resource for saving and retrieving a "checked in" status for an authenticated user.
Example commands:
Check a user's status
curl http://localhost/demos/services-7x-test/docroot/api/v1/drupalsquare/1 -H "Accept: application/json"
Check-in a user
curl http://localhost/demos/services-7x-test/docroot/api/v1/drupalsquare/checkin -X POST -H "Content-type: application/json" -H "Accept: application/json" -d '{"uid":1}'
Additional resources
An API that exposes data and actions to a 3rd party is only as good as the documentation for that API. Without good documentation no one will be able to make use of the API you just spent so much energy creating. In this lesson Joe shows some of his favorite API documentation examples and then walks through creating some basic documentation for the resource we created in the previous lesson.
Additional resources
Example - GitHub API Documentation
Example - Recurly Documentation
http://apiary.io - tool to assit in writing good documentation
This week, you'll take your HTTP response and request skills to the next level as you learn how to tackle common use cases such as filtering returned data to get only what you need and authenticating requests to get data behind a login. In this installment of our series, Building Web Services with Drupal 7, Joe Shindelar will walk you through how to query, test, and authenticate your D7-backed web services.