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 https://raw.githubusercontent.com/Homebrew/install/master/install)"
## Optional: Install iTerm and Oh My ZSH
iTerm has some extra functionality for your terminal: https://www.iterm2.com/
Oh My Zsh: https://github.com/robbyrussell/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/Cellaremail@example.com/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" ==> firstname.lastname@example.org To enable PHP in Apache add the following to httpd.conf and restart Apache: LoadModule php7_module /email@example.com/lib/httpd/modules/libphp7.so <FilesMatch \\.php$> SetHandler application/x-httpd-php </FilesMatch> Finally, check DirectoryIndex includes index.php DirectoryIndex index.php index.html The php.ini and php-fpm.ini file can be found in: /usr/local/etc/php/7.1/ firstname.lastname@example.org 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@example.com first in your PATH run: echo 'export PATH="/firstname.lastname@example.org/bin:$PATH"' >> ~/.zshrc echo 'export PATH="/email@example.com/sbin:$PATH"' >> ~/.zshrc For compilers to find firstname.lastname@example.org you may need to set: export LDFLAGS="-Lemail@example.com/lib" export CPPFLAGS="-Ifirstname.lastname@example.org/include" To have launchd start email@example.com now and restart at login: brew services start firstname.lastname@example.org Or, if you don't want/need a background service you can just run: php-fpm
## 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
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 /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin $ ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /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 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!