In August 2016, Taylor Otwell announced Laravel Valet, a minimalist development environment that extended Mac’s built-in PHP server. While it isn’t meant to serve as a replacement to tools like Docker or Vagrant, it does provide a quick and easy way to get a Magento 2 installation running on macOS with minimal effort.
Thanks to @lazyguru, Valet ships with a Magento driver by default
Setting up Laravel Valet on macOS
To get started, we’ll use Homebrew to install or update the current PHP version on our Mac. If you don’t already have Homebrew installed, you can do so with the following command.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
We’ll go ahead and update brew to verify that we’re on the latest version
Next, we’ll install PHP 7.0. At the time of this article, Magento 2 doesn’t support PHP 7.1, so we’ll stick with 7.0 for now.
brew install homebrew/php/php7
Now we’re ready to install Valet. If you don’t have composer on your machine, go ahead and install it with
curl -sS https://getcomposer.org/installer | php
To install Valet, run
composer global require laravel/valet
You’ll also need to make sure that the composer bin directory is in your system’s PATH.
valet install to finalize the installation. This will install the core valet components, DnsMasq, and setup services to launch on startup.
Using Homebrew, you have a few options for your database server. You can stick with the default MySQL or you can use Percona or MariaDB by running
brew install percona- server or
brew install mariadb
Linking Valet to our Magento Installation
Change to your local Magento installation and run
valet link magento2. This will setup a domain at
http://magento2.dev where we can view our site.
Verifying the installation
After restarting Valet, verify the installation by changing to your Magento installation and running
If the driver was installed correctly, you should see
This site is served by [Magento2ValetDriver].
Until Docker figures out a way to deal with latency issues on macOS, Valet seems to outperform a typical Docker configuration. If you plan on building a headless Magento integration, Valet provides a quick way to access the REST API locally without having to spool up separate environments for testing. The DnsMasq integration can help prevent ugly host file edits while still providing the same functionality.