Yesterday, Taylor Otwell released Laravel Valet, a development environment for Mac minimalists. It didn’t take long before Taylor also released a driver for WordPress, which is why I thought I’d do a write-up here on the blog.
Valet is a super simple approach to development environments. I use Vagrant every day and I love it. It’s just that sometimes… Sometimes you just need something simple that just works! Well, Valet is that. If you are just curious to know more about Valet, jump to the bottom of this post, where I go over a few general questions. Feel free to add any additional questions you might have in the comments.
Note: Valet is Mac only. If you are looking for a super simple cross-platform alternative, check out Wocker.
Before we get started, you can also check out Adam Wathan‘s awesome ad spot for Valet:
Installation
Installing Laravel Valet is very straight forward, given you have a few things already set up on your Mac. I’m not going to go over the process here, because Taylor already wrote some great documentation for you.
The 2 main things you need in order to install Valet are Homebrew and Composer. I couldn’t get it to work with my current version of Homebrew, so I scrapped it and reinstalled it. After that everything worked like a charm. You are going to use Homebrew to install PHP 7 before you install Valet. As for the database, I followed Taylor’s recommendation and installed MariaDB (a better alternative to MySQL) with Homebrew as well.
Setting up a WordPress site
Valet has a WordPress driver (you can create your own drivers if you need something else), so out of the box, it supports running WordPress sites. It’s actually smart enough to figure out which driver to use, so there’s zero configuration needed, other than the usual WordPress stuff.
There are 2 ways Valet can serve your sites: The park
or the link
option. The park
option can be used to add a whole folder to Valet. Every folder in there will then be mapped to a site and get it’s own .dev domain. So if you add ~/Sites
to Valet and there have a folder in there named wp-valet
, the content of that folder will be served when you visit http://wp-valet.dev in your browser. No setup required! The link
option can be used to serve a single site, without adding a whole directory.
Here’s how I used the park
command to add a folder to Valet:
$ mkdir ~/Sites
$ cd ~/Sites
$ valet park
That’s literally it. Then I went ahead and used WP-CLI to install WordPress:
$ mkdir wp-valet
$ cd wp-valet
$ wp core download
I then jumped over in Chrome and visited http://wp-valet.dev and that’s it! Super simple.
Sharing your site (this is cool)
Valet can do something that’s pretty cool, by using ngrok. Imagine that you’re working on something locally that you need to quickly show someone. What do you do? Set up a staging site just for that? On a subdomain? On another domain? Just a screenshot maybe? Well, if you’re using Valet, you can just type valet share
in your Terminal app and Valet will setup a secure tunnel to your localhost and give you a link to share! Pretty cool stuff.
When you’re done sharing, you just hit Ctrl-C and the tunnel will be closed again.
A few more things
Here are a few answers to some questions you might be having. Please ask questions in the comments and I’ll add them here as well!
Does Valet mess with my hosts file?
Nope. It uses dnsmasq to capture all requests to .dev domains (unless you have an entry for them in your hosts
file).
Which server is Valet running on?
Valet is using the built-in server in PHP, which was introduced in PHP 5.4. Valet runs on PHP 7.
When should I use Valet and not Vagrant?
I personally use Vagrant for larger projects, where I have a lot of dependencies, such as older versions of PHP, and like to work in an isolated environment. What I intend to use Valet for is those quick and dirty things, where you just need something to run right now. I don’t like installing to much stuff on my Mac, so if that’s required, I’d rather work in a Vagrant box.
Have more questions? Just post a comment below and I’ll add it here!
I hope you found this post useful! Now, go check out Valet.
WP Pusher – Git for WordPress
This post was brought to you by WP Pusher.
WP Pusher keeps all your client websites up-to-date whenever you push a change to GitHub or Bitbucket. Visit our website to learn more about WP Pusher.
This is great, Out of curiosity, for those of us that do have .dev in our hosts file (thanks to desktop server etc), is there a way for it to use something other than .dev?
Yes, very soon! 🙂 https://twitter.com/taylorotwell/status/728601803902746625
…and because .dev is going to become a valid gTLD
This is pretty awesome thanks for sharing this. I wasn’t initially able to get `valet install` to work, but then I did `export PATH=”~/.composer/vendor/bin:$PATH”` and it was able to run just fine.
This is very cool and amazingly quick, although it’s not seeing the DB (I installed MariaDB and am using root, blank, localhost.
nm. needed to start mariadb. `brew services start mariadb`
Laravel Valet seems great, but am having some trouble getting it up and running. Must I have Laravel installed somehow? Terminal does not recognize “laravel” commands. Also, how do you know the credentials and database name for mariadb database?
You have to make a database. You can use homebrew to install phpmyadmin. I used Sequel Pro to connect to the database server and made a database there.
In Sequel Pro I used “127.0.0.1” as the host and “root” as the username, with no password to connect.
Also, no need to use “laravel” commands. You should be able to use “valet” to make that work, I had to modify ~/.bash_profile and add:
PATH=/usr/local/bin:$PATH
export PATH=”$PATH:$HOME/.composer/vendor/bin”
export PATH=”/usr/local/sbin:$PATH”
Thanks Josh, this helped!
I get all the way through the install steps. When I try to run valet install, I just get ‘command not found’. Everything else seemed to go OK. Any ideas?
Please add this to you .bash_profile export PATH=”~/.composer/vendor/bin:$PATH” like Josh explained.
OK, it seems that, because I’m using the Fish shell, some entries in the .bash_profile were causing issues and I couldn’t add the path to composer. I returned to using Bash and now all is well.
As a temp fix, you can also run `~/.composer/vendor/bin/valet install`, if it’s not added to your PATH.
Thanks Peter – it’s all running now and I have to say, I’m really impressed.
This works really well. The one thing it’s failing for me is the command “valet logs” which always says “No log files were found”
Is anyone else having trouble with only getting 404 – Not Found pages? That’s all I get, no matter what I do.
Same here. ‘valet share’ always gives a webpage with “404 – Not Found”. Still to find solution
This is looking great, pretty simply to setup and very fast. A few days ago I am sure I read a post/comment that included some php to rewrite wordpress URLs so they dont contain index.php, for the life I me I cant find it. Was I dreaming ?
Make sure you’re on the latest version. This should have been fixed as far as I know!
I made a video about setting up a local WordPress development environment in seconds (or a couple of minutes tops) with Laravel Valet and a little bit of bash scripting with WP-CLI.
Hope it might help someone: https://youtu.be/Ai-HogVDxq4
Valet isn’t using the built-in PHP server any more, it is using Caddy instead.
Anyone an idea? Login into wordpress with mysite.dev/wp-admin (without trailing slash) gets me broken admin links. The permalinks contain ‘index.php’. Valet is ‘on-latest-version’. Thanks in advance.
Any luck with this? Having the same issue using Valet and Bedrock
Well, at least I always provide the trailing slash or use wp-login.php. It’s just the dev environment so it doesn’t really bother me. You can get rid of ‘index.php’ by rewriting the permalinks. It’s not a problem specific to valet. Have faced the same problems with some Mamp installs.
Hmmm. Still stuck here as I need to access PHP files directly as well. Thanks for the info though!
when I run valet install command it shows me following error.
I had this same issue. You can run ‘brew install dnsmasq’ separately then try ‘valet install’ again and it’ll work fine 🙂
Does it work with XDEBUG and PhpStorm?
How did you get the database connected? I’ve got everything installed, but WordPress obviously needs to be set up. How could you possible download the core and automatically have everything installed in the database already?
Hey Peter, thanks for this post and bringing Valet to my attention!
I’ve created a little tool for Valet that might help speed up the workflow for other WP developers https://github.com/aaronrutley/valetpress
VVV + VV for Vagrant seems much quicker. Am I missing something?
Looking great, pretty simply to setup and very fast.