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:
You'll get a directory location returned similar to this if it's already installed:
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:
you should get a return showing PHP 7.3 that looks something like this:
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 firstname.lastname@example.org
And then start it as a background service:
brew services start email@example.com
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:
Install Valet, and setup DnsMasq, Nginx and PHP:
Let's test Valet to see that it's working by pinging a fictitious domain:
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 firstname.lastname@example.org started Jack /Users/Jack/Library/LaunchAgentsemail@example.com nginx error root /Library/LaunchDaemons/homebrew.mxcl.nginx.plist firstname.lastname@example.org error root /Library/LaunchDaemonsemail@example.com firstname.lastname@example.org started Jack /Users/Jack/Library/LaunchAgentsemail@example.com
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:
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:
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:
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 firstname.lastname@example.org:aaemnnosttv/wp-cli-valet-command.git
Alright! We're now ready to add some WordPress sites. In the terminal change directory to /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.