Dev Setup How to set up Vagrant on Mac Published August 24th, 2019

Here are some steps and notes I took recently when setting up Vagrant for Laravel development on a Mac

How to set up Vagrant on Mac image
Vagrant virtual environment

I recently started a new job at Phone2Action and am setting up a new macbook pro for software development. These are some of the steps I’ve taken to get up and running with Vagrant on a new Macbook. Vagrant is a virtual environment on your computer. You can install Vagrant Boxes to have a common development environment with other developers on your team. By installing and using a Vagrant box it can eliminate the need to install many other softwares like PHP, MySQL, Redis etc.

Install Xcode and Xcode developer tools.

Conventional wisdom is to run xcode-select --install to install Xcode. I ran into an error that “Xcode is not currently available from the Software Update server”. I then had to download Xcode and the developer tools with my Apple Developer account here. It takes a while to download but is an important first step for software development.

Install Homebrew

Once Xcode is installed install Homebrew with the one liner from their website:

/usr/bin/ruby -e "$(curl -fsSL"

Optional: Install iTerm and Oh My ZSH

iTerm has some extra functionality for your terminal:

Oh My Zsh:

Install packages

Once Homebrew is installed you can use it to install lots of important packages for software development. I’ll be using PHP and MySQL with Node.js. These commands install composer, package manager for PHP. Yarn, which is the new new version of NPM. PHP version 7.1 and the AWS command line tools.

$ brew install composer
$ brew install yarn
$ brew install node
$ brew install redis
$ brew install php71
$ brew install awscli 

This is the ending summary from the PHP install:

==> Summary
🍺  /usr/local/Cellar/[email protected]/7.1.30: 513 files, 63MB
==> Caveats
==> libtool
In order to prevent conflicts with Apple's own libtool we have prepended a "g"
so, you have instead: glibtool and glibtoolize.
==> gettext
gettext is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD gettext library & some software gets confused if both are in the library path.

If you need to have gettext first in your PATH run:
  echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.zshrc

For compilers to find gettext you may need to set:
  export LDFLAGS="-L/usr/local/opt/gettext/lib"
  export CPPFLAGS="-I/usr/local/opt/gettext/include"

==> libffi
libffi is keg-only, which means it was not symlinked into /usr/local,
because some formulae require a newer version of libffi.

For compilers to find libffi you may need to set:
  export LDFLAGS="-L/usr/local/opt/libffi/lib"

==> libpq
libpq is keg-only, which means it was not symlinked into /usr/local,
because conflicts with postgres formula.

If you need to have libpq first in your PATH run:
  echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc

For compilers to find libpq you may need to set:
  export LDFLAGS="-L/usr/local/opt/libpq/lib"
  export CPPFLAGS="-I/usr/local/opt/libpq/include"

==> [email protected]
To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/

    <FilesMatch \\.php$>
        SetHandler application/x-httpd-php

Finally, check DirectoryIndex includes index.php
    DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:

[email protected] is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have [email protected] first in your PATH run:
  echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
  echo 'export PATH="/usr/local/opt/[email protected]/sbin:$PATH"' >> ~/.zshrc

For compilers to find [email protected] you may need to set:
  export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
  export CPPFLAGS="-I/usr/local/opt/[email protected]/include"

To have launchd start [email protected] now and restart at login:
  brew services start [email protected]
Or, if you don't want/need a background service you can just run:

Optional: Symlink Sublime Text

Symbolic links help you quickly open applications or programs using the command line. In my case I like to have a file or directory open in Sublime Text (which you can download here) when I type subl filename.

To do this you need to add Sublime Text to your load path. Check the load path location by running echo $PATH. This will show the load paths separated by colons.

$ echo $PATH
$ ln -s "/Applications/Sublime" /usr/local/bin/subl
$ subl ~/.zshrc

This creates a symbolic link or sym link so that you can open Sublime from the command line. This tutorial is super helpful.

Install VirtualBox

Vagrant runs on top of VirtualBox. You’ll need to have it installed on your machine.

Install VirtualBox on a Macbook

Install Vagrant

You can download Vagrant for Mac here.

Move to a folder where you’d like to set up your virtual environment. For example you can make a folder named mkdir vm to run vagrant commands inside of. Install Laravel Homestead by running:

$ cd /yourPathToVagrantFolder
$ vagrant init
$ vagrant box add laravel/homestead

When I tried to run this command the first time I got an error: OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 54. The next morning I ran vagrant destroy and then ran the command to add the vagrant box and it worked. I believe that issue was due to the network. Trying it at a different time of day worked for me.

Once installed clone your project, cd into it and run vagrant up. You may need to run vagrant reload --provision when booting up your machine. Be sure to consult the Laravel Homestead documentation for more notes on running a Laravel 5.8 app with Vagrant and the Homestead box for your development environment!

Related articles