And why is it (currently) Laravel Valet?

One of the main reasons I switched from Windows to Ubuntu for my development workstation back in 2006 was that I was tired of complicated setups for managing local development environments. Because Rasmus Lerdorf, the creator of PHP, spent a lot of time making Linux, Apache, and MySQL the perfect stack for PHP, it’s literally 3 terminal commands and an Apache vhost
configuration file, and you have a working local site. On more recent versions of Ubuntu, you can even just replace the 3 terminal commands with one single command to install the entire lamp-server
stack.
When I started using a MacBook earlier this year, I wanted the same “ease of set up” as I experienced on Ubuntu. I tried every local development environment I could find, and I can finally say I understand why everyone raves about Laravel Valet. It’s straightforward to set up and install and creating new local dev sites is a breeze.
Requirements
To get Laravel Valet working on your Mac, you’ll need to have Homebrew and Composer installed. Each of these has its own simple to follow installation instructions:
Homebrew is one line to install, Composer is a couple of commands to download, and then another to make sure Composer is installed globally, so you can run Composer commands from any location. Once that’s all set up, you can follow the Laravel Valet installation instructions, which is 3 steps:
- Update Homebrew (if you’ve not just installed it)
- Use Homebrew to install PHP
- Use Composer to install Laravel Valet
Valet installs Nginx as your local web server instead of Apache, but that doesn’t really matter, because Valet also makes it simple to create the Nginx virtual host.
One last thing before you can create a dev site, is you need to install MySQL. The Valet docs suggest installing DBngin, but I prefer good old MySQL, which you can install with Homebrew.
brew install mysql
Or MariaDB if you prefer
brew install mariadb
Day to day use
This is where Valet shines. The Valet docs are detailed, but there are only a handful of commands you need to memorize. Once you have the initial software installed, you can provision a new local site in a matter of seconds.
The link command will link a directory to Valet, essentially setting it up to serve files as a local site. In my case, my local dev websites reside in the following directory:
~/development/websites
So if I wanted to create a new local site, I create a new site directory and link it to Valet.
mkdir ~/development/websites/new-site
cd ~/development/websites/new-site
valet link
And that’s it! It even sets up the hosts file based on the directory name, so I can browse to http://new-site.test
and Valet will serve whatever is at the root of the ~/development/websites/new-site directory
.
The secure command will allow you to create and install a local SSL certificate.
valet secure new-site
Valet can do loads more, so I recommend reading the entire Valet doc, but just the ability to provision a new local site, and secure it with a locally trusted SSL certificate, using only a handful of commands, saves me loads of time every day.
You might be wondering then, why I added (currently)
in the intro line to this post. Well, that’s because at the moment there’s something else I’m involved with, which I think will be even easier to use as a local development environment. Given that I think Valet is so great because it’s so simple to use day-to-day, I’m even more excited about this project, for a number of reasons. You’ll have to watch this space to find out what that’s about…
Leave a Reply