Setup Valet On A Mac

March 17, 2021

Setting up Laravel Valet on a MacBook Pro is not too difficult and provides a terrific website development environment that's https:// out of the box. I've used this setup now for a couple of years and I love it. It's fast and easy once you get the steps down. When I'm finished with dev environment and ready to deploy to either another staging environment for client approval or to production, I'll use UpdraftPlus with Migrator add-on to finish the migration.

In this post we'll go through the steps to setup Valet and a dev environment to begin development. Valet only runs on a Mac so for PC users coming across this article, I'm sorry to take your time thus far.

Valet runs using Nginx, PHP 7.3, DnsMasq and uses the .test domain name by default. It also sets your domain to https://mydomain.test upon completion so no messy 'whynopadlock' issues when migrating.

Let's Setup Our Dev Environment

First off, let's get Homebrew up and running. If you don't know if you have Homebrew installed, run this command:

which brew

You'll get a directory location returned similar to this if it's already installed:

/usr/local/bin/brew

If it returns not found then you'll need to install Homebrew using this command:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

The Homebrew package manager will now be installed along with some Xcode command line tools that are needed.

Install Composer, PHP and MySQL

Let's get Composer installed next:

brew install composer

Now to check if and which version of PHP are installed on your computer:

which php

you should get a return showing PHP 7.3 that looks something like this:

/usr/local/Cellar/php@7.3/7.3.21

If you get a response that shows no PHP installed then we'll need to install it:

brew install php

You can choose between MySQL and MariaDB as the database. In this example we're going to use MySQL 5.7 since version 8 is still not well supported:

brew install mysql@5.7

And then start it as a background service:

brew services start mysql@5.7

MySQL will be installed with the user as root with no password.

Install Valet using Composer

Let's get Valet installed now. It's what we're all here for, yeah?

composer global require laravel/valet

We're going to need to configure our Bash shell path so we can easily use Valet from any folder in our Terminal:

~/.composer/vendor/bin

Install Valet, and setup DnsMasq, Nginx and PHP:

valet install

Let's test Valet to see that it's working by pinging a fictitious domain:

ping mydomain.test

A pingback reply will confirm DnsMasq is working properly. Now we'll want to check to see that PHP, Nginx and MySQL are running:

brew services list

dnsmasq   unknown root /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
mysql@5.7 started Jack /Users/Jack/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist
nginx     error   root /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
php@7.2   error   root /Library/LaunchDaemons/homebrew.mxcl.php@7.2.plist
php@7.3   started Jack /Users/Jack/Library/LaunchAgents/homebrew.mxcl.php@7.3.plist

Webroot (projects home) and Park

We'll need a directory or folder to keep our projects. Some people use the traditional Mac ~/Sites directory others use /code or /projects. I created and use ~/projects for my local dev directory. It's located in my user directory. You can use whatever name you wish for your development directory. Let's make that directory now:

mkdir ~/projects

At this point is where Valet Park comes into play. When you designate a directory as the location where your projects will be located using the 'park' command, whenever you create a new development project using Valet, that project will be created in your designated 'park' directory. Let's do that now:

cd ~/projects
valet park

Valet and WordPress Installations

Fortunately, WordPress has a great command line installation tool that fits perfectly with Valet: wp-cli. Let's get that installed:

brew install wp-cli

In a future post we'll take a look at how to setup a bash shell script to install all your most used plugins at the same time as you're installing WordPress with Valet.

We're going to need to increase the PHP memory limit or we'll get a fatal error and we definitely don't want that. Let's find the php.ini config file using this command:

php --ini
vim /usr/local/etc/php/7.3/conf.d/php-memory-limits.ini

Change the memory limits to 2048 in all three places and save the file. You can also use the Nano editor if you're more comfortable with it. I personally like VIM.

Make sure your MySQL is running:

brew services start mysql

Let's add the wp-cli-valet-command package:

wp package install git@github.com:aaemnnosttv/wp-cli-valet-command.git

Alright! We're now ready to add some WordPress sites. In the terminal change directory to /projects

cd ~/projects
wp valet new myNewSite

where myNewSite is your new site name. Valet will automatically create your site with this URL: https://myNewSite.test You can access your new site at https://myNewSite/wp-admin with admin as both user and password.

To remove a site, use this command:

wp valet destroy myNewSite

Editing The Database

I'm not going to get into the specifics of how to edit the installations database but I will say that I use SequelPro to do my editing. You can access the database with the URL 127.0.0.1 using root as username and no password.

ABOUT

I'm Jack Walsh, a professional freelance WordPress developer based in San Diego, CA. One of the things I love is the technology that allows me to travel all over the U.S. and the world with my wife and two dogs yet still stay in contact with my clients. I've been working with WordPress for over a decade. I'm a Codeable certified WordPress expert and have been fortunate enough to work with awesome clients from all over the world. I'd love the opportunity to talk with you about your next custom WordPress project.

GET IN TOUCH

Have a question not listed in the FAQ? Email me at jack.walsh@jw-wpdev.com

Want to discuss your next project?

Let's Talk!
crossmenu