This is a guide on how to set up Laravel Valet on macOS for a WordPress local development environment. Using Valet as a WordPress local development solution has the main benefits of speed, being light weight and using less configurations to go wrong than say a solution like Vagrant.
Valet runs only on macOS and runs directly on top of the operating system not in a virtual container.
The key software components needed are Homebrew; a package manager and Laravel; a PHP framework.
Valet itself has a Nginx, PHP 7.2, MariaDB or MySQL, DnsMasq and by default uses the .test domain name. Once the software is all installed Valet itself will launch automatically on start up.
Set Up Local Development Environment
First up is to install Homebrew so the key parts of the web stack such as php and mysql/mariadb can get installed easily.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
This will install Homebrew package manager and Xcode command line tools if not already installed.
Install composer with Homebrew
brew install composer
Get PHP and MySQL set up
brew install homebrew/core/php
Install mysql/mariadb – background service works after restart
brew install mariadb
Start it as background service
brew services start mariadb
MySQL/MariaDB installs as user root with no password.
Get Laravel and Valet set up
composer global require "laravel/installer"
Install Valet with composer
composer global require laravel/valet
Make sure your macOS shell path has the following location, this will allow you to easily use valet commands on the command line – if you don’t include it you will need to prefix all valet commands with ~/.composer/vendor/bin/
Now it will install dnsmasq and set up nginx and php and start valet, some basic valet commands below…
ping blah.test for 127.0.0.1
A responding ping will verify dnsmasq and the other components have been successfully set up.
To upgrade Valet
composer global update
Webroot & park
Probably the best method for a webroot directory is to use the Sites folder in your home, this was a traditional webroot in the past of the macOS user account filing system – if one is not their either make one in the Finder or via the Terminal
Register the Sites folder with Valet, so any top level folders will be treated as a serving site – use the park command
There is also a valet link command that allows a directory somewhere else in the filing system to serve its content as a webroot, it does so by putting a symbolic link in the park directory – Sites.
To set up new Laravel project sites you can use the command
laravel new sitename
The first site created this wat takes a while with a number of downloads, when it is done a new http://sitename.test is viewable in the browser – but what about with an actual WordPress install? – see next.
WordPress and Valet
Increase you PHP memory size, especially if you installed PHP with Homebrew – otherwise a fatal error will occur when installing wp-cli-valet-command package, find your PHP memory limits .ini config file
Change limits to 512M in all 3 places
Also make sure your MySQL or mariadb is running…
brew services start mariadb
Once you have wp-cli add the wp-cli-valet-command package
wp package install [email protected]:aaemnnosttv/wp-cli-valet-command.git
Once this is installed you are ready to create some WordPress sites…
To install a new site, move into your Sites folder and run a wp valet command
wp valet new newsitename
This will set up https://newsitename.test ready to go WP-Admin defaults are admin/admin for username and password.
All new sites are by default set up with https – to set one up just as http – run…
wp valet new newsitename --unsecure
To remove a site…
wp valet destroy newsitename
For more commands and options check out the GitHhub repo for wp-cli-valet and also you can create custom sites with certain theme, plugins etc by rolling your own bash scripts.
To deal with MySQL via phpmyAdmin – create a new site
wp valet new phpmyadmin
So now you have a https://phpmyadmin.test – remove all the WordPress files and download and move into the folder the latest phpmyadmin files – if your mysql instal is no password then change the config file as prompted to AllowNoPassword. Now all your databases are easily accessible.
You can take WordPress site installation further with Valet by adding a bash script that includes further refining the install with plugins and themes tailoring – see the next article on Valet, wp-cli and bash scripting.