Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Elian Van Cutsem
Elian Van Cutsem

Posted on • Edited on • Originally published atelian.codes

     

Using Laravel Valet for local PHP development

This week I've been developing PHP and Twig at my internship atvBridge, since we're using a big pile of sourcecode, Docker doesn't perform as well. To fix thisBramus told me about a tool called Valet. So I went on the search to configure and install Valet.

Installing Valet

Installing Valet is actually really easy. They have incredibledocumentation (as usual with Laravel).

You can simply install it by usingcomposer global require laravel/valet if you've installedHomebrew, PHP andComposer, else you should install those first (but also that is very easy). Once that's done, simply runvalet 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 fromlocalhost or172.0.0.1.

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

Valet Link

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 runvalet link and the name of the directory will be used as domain. For insance:

cdlaravelsitevaletlink
Enter fullscreen modeExit fullscreen mode

Now when you open your browser and go tolaravelsite.test. It will magically appear on the screen! awesome right!

You can also name a link by runningvalet link <name>. For instance:

cdlaravelsitevaletlinknewsite
Enter fullscreen modeExit fullscreen mode

Now it's available atnewsite.test

It's amazing!

Valet use

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!

Just runvalet use php@version 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.

Valet Secure

Tired of the stupid browser notification that localhost isn't secured? Me too. Valet also has a nifty solution. Runvalet secure <name>x and it will install a certificate for you.

It's insane how easy this all is!

valet-env.php

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 calledvalet-env.php and will use it to configure and use environment variables

For instance:

<?phpreturn['newsite'=>['APP_ENV'=>'dev',],];
Enter fullscreen modeExit fullscreen mode

Now when you'll opennewsite.test in your browser, it'll have the dev environment!

Read the post about environment variable from Bramushere

Read thefull documentation here!

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Core Astro Team | devs.gent meetup organizer | BeJS, React Brussels & React Paris household figure | public speaker | Podcast Host
  • Location
    Ghent, Belgium
  • Education
    Bachelors in ICT, specialisation in Web & Mobile development
  • Work
    Core Astro Team at The Astro Technology Company
  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp