Mac OSX Dev Environment (LEMP stack) Using Vagrant and Homestead

Important Notice: This environment is a LEMP stack and useful for PHP frameworks like Symfony, Laravel, Zend, etc. This may not be what you are looking for so just wanted to advise before you read my ramblings!

I won’t go into great detail about Vagrant and Homestead as if you are here you probably know about them anyway.

In short Vagrant is a tool that allows you to setup and manage Virtual Machines. From Vagrant you can get all sorts of cool and exciting boxes, but for a LEMP stack I have found that the Homestead box is my favourite.

Homestead is a vagrant box from the good people at Laravel that ships with Nginx, PHP 7.1, MySQL, Postgres, Redis, Memcached, Node, and loads more goodies.

So, let’s get cracking…

Install Vagrant

  1. Install VirtualBox 5.1 (you can install VMWare or Parallels and they all have versions for both Mac or Windows, but VirtualBox is my preferred choice).
    • If you use homebrew on a mac you can also install by running brew cask install virtualbox.
  2. Install Vagrant.
    • If you use homebrew on a mac you can also install by running brew cask install vagrant.
  3. Optional: If you want an easy way to manage your vagrant machines on a mac install Vagrant Manager.
    • If you use homebrew on a mac you can also install by running brew cask install vagrant-manager.

Grab the Homestead Vagrant Box

  1. Run vagrant box add laravel/homestead
  2. Grab a cup of tea, coffee, favourite energy drink, whiskey or whatever else you may like to drink while watching a progress bar move…
  3. Once the box has been downloaded you will be prompted to chose what provider you want to use. In my case it was virtualbox. You can always change this at a later date in the homestead.yml file and use any of the following values: virtualbox, vmware_fusion, vmware_workstation, or parallels.

Setting up Your Project

With Homestead it can be setup globally, so you can configure it for all the different sites and projects.

However, that is not how I like to role. It is a personal choice, but I work on a wide variety of different projects and I prefer creating an environment per project, so I have full control over each individual environment.

If you want to setup a single Homestead instance and manage your projects through that then there is some great help on the Laravel site.

  1. Create a folder for your project to sit in and jump on into it.
  2. Install Homestead for your project by requiring it through composer: composer require laravel/homestead --dev
    • If you haven’t got composer installed visit the composer site.
  3. Now Homestead is installed and in your vendor folder you can use the make command to generate the Vagrantfile and Homestead.yaml file in your project folder.
    • For Mac / Linux users run php vendor/bin/homestead make
    • For Windows users run vendor\\bin\\homestead make
  4. Run vagrant up and your site should be up and running.
Possible Problems
  • read: No such file or directory @ rb_sysopen - .ssh/id_rsa (Errno::ENOENT)
    If you get a similar error it is usually because when you first use the make command an SSH key location is specified by default in the Homestead.yaml file. If you have not set one up you will need to run ssh-keygen -t rsa -C "your@emailaddress.co.uk".

Offcanvas

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.