Using Laravel Valet for local PHP development
This week I’ve been developing PHP and Twig at my internship at vBridge, since we’re using a big pile of sourcecode, Docker doesn’t perform as well. To fix this Bramus told me about a tool called Valet. So I went on the search to configure and install Valet.
Installing Valet is actually really easy. They have incredible documentation (as usual with Laravel).
You can simply install it by using
composer global require laravel/valet if you’ve installed Homebrew, PHP and Composer, else you should install those first (but also that is very easy). Once that’s done, simply run
valet install and Valet will install and start.
Now that valet is installed and started you’ll be able to ping any
.test domain and it’ll answer from
Valet also starts when you boot your computer and will run as a background process with only 7mb of RAM!
Also, Valet is MacOS only
So installing is easy, so mapping a domain shouldn’t be hard right! just cd into the directory you want to run as a site and run
valet link and the name of the directory will be used as domain. For insance:
cd laravelsite valet link
Now when you open your browser and go to
laravelsite.test. It will magically appear on the screen! awesome right!
You can also name a link by running
valet link <name>. For instance:
cd laravelsite valet link newsite
Now it’s available at
So, imagine that you’re developing a website on your local machine with the newest version of PHP, but the server you’ll be deploying to uses a much older PHP version. You don’t want to put in the work to install a new old version right? Valet got you covered!
valet use [email protected] and valet will use that version. If you don’t have the version installed locally, it will install it for you.
But ofcourse, sphp is a valid choice too.
Tired of the stupid browser notification that localhost isn’t secured? Me too. Valet also has a nifty solution. Run
valet secure <name>x and it will install a certificate for you.
It’s insane how easy this all is!
Ofcourse if you’re a somewhat more demanding user. It can be interesting to use and create custom environment variables.
Valet has support for a file called
valet-env.php and will use it to configure and use environment variables
<?php return [ 'newsite' => [ 'APP_ENV' => 'dev', ], ];
Now when you’ll open
newsite.test in your browser, it’ll have the dev environment!
Read the post about environment variable from Bramus here
Read the full documentation here!
Written by Elian Van Cutsem on 02/12/2021 20:48← Back to all posts