- About the author
- Jonathan Christopher
Every local development environment is based on a stack of some sort. My goal here was to remove as many barriers to development as possible, and for me that aligns with installing everything locally. Local for me equates to OS X, so everything in this series is based on that setup.
Homebrew on OS X is one of your best friends as a developer. Touted as The missing package manager for macOS Homebrew allows you to easily install various UNIX tools that aren’t included with macOS.
Installation instructions are kept at the top of Homebrew’s home page, at the time of this writing it’s a single command you can enter into your Terminal prompt.
The E in MEMP stands for Nginx (because it’s pronounced engine-X) which is supported in a few different ways through Homebrew. While there is a default
nginx tap (i.e. Homebrew package) available, I prefer to use the community version because it offers a module that’s essential for a customization outlined in MyLocalDev Part 4: Differentiating Your Local Environment.
If you’ve already got
nginx installed via Homebrew, it’s easily uninstalled by executing the following on your command line:
brew uninstall nginx
Once uninstalled, we can install a Valet-compatible version of Nginx called
nginx-full with a couple of modules like so:
brew install nginx-full --with-sub --with-http2
Installing in this way includes support for HTTP/2 which is necessary for Valet, along with another module that allows us to customize content served by our local Nginx installation. For more information on why this is necessary check out MyLocalDev Part 4: Differentiating Your Local Environment.
Homebrew makes it really simple to install PHP and MySQL with just a couple of commands, but I found that a slight customization is needed to ensure that SSL works when performing certain operations.
I discovered that without this customization, migrations run through WP Migrate DB Pro don’t always work as expected when you’re pulling from (or pushing to) an environment over HTTPS. There is documentation from WP Migrate DB Pro about SSL issues that includes a link to a Valet GitHub Issue that has a comment from lekkerduidelijk that had a fix that worked great for me. Hello open source!
If you already have PHP 7.1 installed via Homebrew like I did, you’ll need to remove it first. Don’t worry, this will not break Valet!
(If you’re running PHP 7.0 instead of 7.1, simply replace
php71 in the following commands)
brew unlink php71
brew remove php71
brew uninstall --ignore-dependencies php71
This will fully remove your existing installation of PHP 7.1, allowing for a reinstallation of PHP 7.1 using OpenSSL.
The commands that worked for me are as follows, each command executed in the following sequence on the command line:
composer global require laravel/valet
brew install openssl
brew install --with-openssl curl
brew install --with-homebrew-curl php71
brew services start homebrew/php/php71
export PATH="$(brew --prefix homebrew/php/php71)/bin:$PATH"
php -i | grep "SSL Version"Should return SSL Version => OpenSSL/1.0.2k
valet secure mywebsiteWhere mywebsite is the directory name of the site you want to serve over HTTPS
This one’s much easier:
brew install mysql
Done! To ensure MySQL starts and restarts when you reboot your machine execute this command:
brew services start mysql
Connect to the database at
127.0.0.1 with a username of
root and an empty string for the password.
Installation of Valet itself is just a single command as per the Valet Installation instructions:
Once Valet is installed, the last thing you need to do is tell Valet where it should look for your sites.
On your command line, change directories to where you store your sites (
cd ~/dev for me) and execute this Valet command:
This will tell Valet to look in
~/dev for folders that match the URL you enter in your browser. The default TLD is
.dev so if you have a folder
http://mysite.dev/ into your browser will have Valet map that request to
~/dev/mysite and it’s as easy as that!
To have Valet serve a site over HTTPS first see the note above about ensuring OpenSSL support and then execute
valet secure mysite
mysite is the directory name of the site you want to secure. Too easy.
This article is part of a MyLocalDev series all about local web development on OS X. Check out the other articles in this series: