Setting Up a new Macbook Pro for Local PHP Development

It’s easy to forget all the stuff you have to do to a brand new machine to get it ready to develop on. I was fortunate enough earlier this year to get a brand new Macbook Pro (2019 edition) to replace my trusty, if dated, 2015 edition. Since there was a ton of stuff to install and configure, I figured I’d take the opportunity to thoroughly document all the things I did to go from brand new out of the box to ready for active PHP / Drupal development.

Initial Work

I’m going to run through these pretty quickly, but they shouldn’t be ignored.

  1. Ensure all necessary security precautions are taken (e.g. secure password on your account, VPN configured, antivirus / firewall configured, etc.)

  2. Run all outstanding Mac OS updates right off the bat

  3. Sign in to (or sign up for) Apple account

  4. Download / Install XCode from App Store

  5. Install other relevant software (e.g. your IDE of choice, password manager, etc.)

Setting Up for Development

Generating a new SSH Key

The first “real” thing I always do on a new machine is generate a new SSH key. You can do this via your terminal using the following command:

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

The email address in this example should be the one you have used for your account on such services as Github, Gitlab, etc. If you use different email addresses on different sites, you may need a different SSH key for each.

Once generated, I start logging into the services I’ll need access to (e.g. Github, your web hosting, Drupal.org, etc.) and uploading the SSH key. if I still have my old computer in my possession I’ll hold off on removing the old key, but I’ll still create a new one.

Protip: Github has incredible documentation on SSH keys and security. This is my go to source for command reminders and help!

Install Homebrew

Homebrew is one of my favorite development tools. I don’t use it “daily” but when I need it, it’s a lifesaver. Basically, Homebrew is a dependency manager for your OS and it makes it a ton easier to install development packages and/or change versions of bundled packages that come with your OS (e.g. PHP version).

You can install Homebrew with the following command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

While Homebrew isn’t stricting speaking required, the rest of this guide will assume you’re using it AND it drastically simplifies what is to come.

Once completed, you’ll see something like this:

Homebrew install successful!

Homebrew install successful!

Install Composer, Git, and PHP

Now that we have Homebrew, we can accelerate the install of packages by grouping them together. For instance, let’s install Composer, Git, and PHP!

brew install php git composer

Note that this process will install the most current version of PHP (for me in 2020 this was PHP 7.4). Once the install completes, you can immediately run php, composer, and git commands from a new terminal session. This is another huge benefit of using Homebrew (it just works).

Homebrew installed PHP 7.4 by Default

Homebrew installed PHP 7.4 by Default

You can manually tweak the specific version of PHP by running a Homebrew command like:

brew install php@7.3

This will pull down the necessary dependencies and the package for this explicit version of PHP. I can then swap out my installed version of PHP (in this case, I can swap out PHP 7.4 with PHP 7.3).

brew unlink php 
brew link php@7.3 --force
Downgraded to PHP 7.3

Downgraded to PHP 7.3

Install Composer (Recommended) Packages

There are a couple of global composer packages that I recommend to help improve composer performance. Theoretically this will be less of a thing in Composer 2.0 but until that comes out, these are worth it!

composer global require hirak/prestissimo:^0.3
composer global require zaporylie/composer-drupal-optimizations:^1.1

Up The PHP Memory Limit

A common composer problem is that composer is beholden to the PHP memory limit on your machine. I highly recommend upping the memory limit (mine started at 128MB on a brand new machine) to at least 2GB (2048MB). You can do so by following my guide in this post.

Preparing for Virtualization

The next big round of installation really surrounds the type of development you’re doing. At this stage, I installed both the necessary dependencies for Vagrant (so I could run Drupal VM) and Docker Desktop (so I could run Lando and DDev). Obviously your miles may vary here depending on what solution you use for containerization / virtualization.

Warning: Sudo Requirements

Once you wade into the these next installation sections, you will begin needing sudo / administrative access to your local. This is a common blocker for some organizations that prevent some folks from running local development environments as their company’s security policies prohibit their developers from having admin access.

Protip: If you can’t get sudo access to your machine, DrupalVM definitely won’t be an option for you. It requires sudo every time you start / stop the VM. Lando, Docksal, and DDev likely need sudo to install and get the requirements setup, but don’t usually need it for daily operation (so they may be better options for you if you don’t have persistent administrative privileges on our host machine).

Installing Vagrant, Ansible, and Virtual Box for DrupalVM

For DrupalVM you’ll want all of these!

brew cask install vagrant
brew install ansible

For VirtualBox, I would confirm which version is currently supported by DrupalVM via the docs and download directly from the VirtualBox page.

There are a few other recommended plugins recommended for DrupalVM. Those are:

vagrant plugin install vagrant-vbguest

Installing Docker Desktop for Lando, DOcksal, and DDev

I’ve found that Lando is a bit more opinionated about Docker Desktop version than Docksal and DDev (and I use it a bit more frequently). So, I would strongly urge you to review what version of Lando you plan on installing and then confirming what version of Docker Desktop it supports. I have, on more than one occasion, installed a version of Docker Desktop that Lando doesn’t like.

Unlike DrupalVM (which is added via composer as a project dependency) Lando, Docksal, and DDev all get downloaded and installed on your machine. So make sure you snag the installers for those as well!

Note: At the time of this writing, Lando tends not to keep their Homebrew presence up to date. DDev does. So, if you’re going to install Lando I would do it off their site. DDev will tell you to go download it from Homebrew.

container.jpg

Congratulations! You have turned your Macbook into a proverbial container store (that is ready for all your local development needs).

The next step from here is to actually start pulling down git repositories, building VMs, and firing up some code. I’ll do deep dives on each of these containerization solutions in future blog posts!

Finally, a shout out and thanks to folks like Jeff Geerling, Drud, FFW, and Tandem for for all the work that goes into keeping DrupalVM, DDev, Docksal, and Lando (respectively) up and running (and the many many other contributors to each that I didn’t explicitly call out here). The Drupal world is so much better today than it was a decade a go when I first started thanks to these incredible tools!

Photo by Tim Sullivan from StockSnap

Related Content