Setting up your Mac with Vagrant and Puphpet for Drupal Development

Setting up your Mac with Vagrant and Puphpet for Drupal Development

I’m always a bit behind with development trends, mainly because working for yourself or small businesses, you rarely have the luxury of spare time to experiment and tend to  stick with what you have to get the job done.

For a couple of reasons I wanted to finally try some sort of new development setup and thought it was high time to look into a Vagrant style setup. These reasons were:

  • I have a little more spare time
  • I am about to embark on a bunch of new development projects
  • I don’t like having redundant extensions littered around my computer
  • I anticipated the updating my Mac would probably break my fairly highly tuned development setup, so it seemed a good time to prevent this happening again
  • I like to learn :)
I have only really just got settled into using Homebrew and love it, so I was slightly sad to be using it less, but it will still get used for other tasks. I am (currently) predominately a Drupal developer, so this will be slightly skewed to that sort of setup, but you may still glean some other more general tips from the steps that worked for me. I like to use GUIs and neatly packaged options as much as possible, so I will often take myself down those paths.

Installing Vagrant

I ended up following the instructions found on Sourabh Bajajs Mac OS X setup guide as it utilised Homebrew (sort of) and added a Vagrant GUI, which all made me very happy.

 

Installing and setting up Puppet

Installing Vagrant was a pretty easy step, but after this I was a little stumped as to next best steps and was still only partially understanding what it was I was really aiming for. I knew that Puppet was the next step but didn’t really know where to start. I had seen Druphpet mentioned at DrupalCon Amsterdam and thought this would be a good place to start, especially as I had a lot of trouble getting Puphpet (which Druphpet is based upon) to work, mainly due to an Ubuntu problem it seems. After installing Composer (with Homebrew of course!) Druphpet worked fine, but I found that (personally) it installed a lot of things I didn’t really need.

After a lot of trial and error, I ended up taking Druphpets config.yaml file, customising it to my needs and then pasting it back into Puphpet to get the zip file that I needed and that worked perfectly.

You can find my config.yaml file here.

One of the other issues I found, and I’m not entirely sure what is ‘best practise’ here, was where to download my Puphpet zip file to. This is important, because when you create your Vagrant box based upon it, it needs to know where to find it and if it moves, the creation process will fail. So I recommend you move the folder to its permanent home before setting up your Vagrant box. For me, I have placed them alongside my Virtual Machines.

As I installed Vagrant Manager, all I really need to now do each time I want to start developing is fire up my Vagrant box from the handy menu item.

Image

Database and Host connections

Most configuration happens within the config.yaml file, which I really love and it appeals to my sense of ‘containerising’ where I undertake my work. However, you will still need to setup your hosts file (/etc/hosts) so your Mac knows where to find site urls you enter into your browser, in my case it looks like this (The IP seems to be standard with Vagrant, but it may be different for you):Image

Following my love of GUIs, I use SequelPro for database management and as you are effectively connecting to another server, you can no longer use a standard ‘Localhost’ connection to connect to your database. I found this Coderwall post a good start for me, but make sure you use your own details of course. Now my SequelPro connection settings look like this:

ImageAll that remains is to import your databases and existing code. Code is really easy thanks to the Vagrant shared folder and all you will probably need to do is move it from the old location to the new.

Cleaning Up

I hate having duplicate versions of things lying around on my computer, so next step for me (once I was sure I had copies of everything) was removing all my old copies of MySQL, PHP etc. If you have been using Homebrew, you can probably just brew remove everything, any other extensions you may have installed I will have to leave up to you. If you’re especially pedantic like me (and have been moving your Mac setup from one machine to another for over a decade), digging around hidden folders you’re likely to find remnants of config files, binaries and other miscellany, I took a chance and deleted anything I found, but I’ll leave that up you!

I would love to be able to remove Mac OS Xs built in PHP and Apache, but I haven’t figured out if that’s possible yet.

Next Steps

I use Digital Ocean for hosting, which you can theoretically push your Vagrant boxes straight to for production (I think) and it’s these next steps I want to investigate more, i.e., Deployments etc. I gather this is the domain of tools such as Docker and Ansible, but I’m still figuring that out.

Bonus! Get rid of 20gb of Windows installs

As part of my explorations I came across this awesome tool for testing with Internet Explorer on non-Windows machines. It’s not based on Vagrant, but is VM based, so thought I would throw it in to the mix and it enabled me to delete my 20gb Windows 8 Virtualbox that I used just for Internet Explorer. That made me very happy, however you will still end up with about 5gb of disk space consumed.