An Introduction to Laravel Valet

This week we will see a more interesting topic of “Laravel Valet”. It is a local development environment for Mac developers. There is no need of installing Vagrant, Apache, Nginx and no changes need to be done in /etc/hosts file. The most special feature of using Valet is that you can even share your sites publicly so that it can be viewed from anywhere in the world. Let’s see the step by step installation and the configurations that need to be done.

Installation

Installing Valet is very easy, it requires Mac operating system, composer and latest version of Homebrew.

  • Install or update Homebrew to the latest version using brew update.
  • Then install PHP 7 by,

               brew install homebrew/php/php70

  • Install Valet with Composer using.

               composer global require laravel/valet

  • Make sure the ~/.composer/vendor/bin directory is in your system’s “PATH”, you can check this by running:

               echo $PATH

If you can’t see it there, then you need to add this to your ~/.bash_profile:

               export PATH=$PATH:~/.composer/vendor/bin

  • Finally, run the following command,

               valet install

Serving Valet Site

  • After Valet is installed, create a new folder to hold all your sites at “~/Projects”. cd into this directory:

               cd ~/Projects

  • Next run the Valet park command:

               valet park

This command will register your current working directory as a path that Valet should search for sites.

  • Next, create a new Laravel site within the parked directory:

               laravel new TestValet

Once it finishes installing visit TestValet.dev in the browser.

If you want to remove the parked directory from the parked directory list by using the command:

              valet forget ~/Projects

Sharing Sites

Using Valet, you can share your local sites with the world.

To share your site, navigate to the site’s directory in your terminal and run the following command:

valet share

A publicly accessible URL will be inserted into your clipboard and is ready to paste directly into your browser. That’s it.

 

2

 

 

1

 

To stop sharing your site, hit Control + C to cancel the process.

Sites outside of your parked directory

You can link the projects in other places on your file system by using “link” command.

               cd ~/Laravel-Projects/TestBlog

               valet link TestBlog

Now you can hit TestBlog.dev in the browser and this site will load.

If you ever want to see a list of linked sites Valet offers the following command:

               valet links

Then if you ever want to remove one:

               valet unlink TestBlog

Securing a Valet site

Valet uses plain HTTP by default and with the release of 1.1.9 you can now easily serve sites over HTTPS by running:

                valet secure TestBlog

Then to revert back to HTTP:

               valet unsecure TestBlog

This is all managed by Caddy Server.

You can start, restart and stop the Valet daemon by

              valet start

              valet stop

              valet restart

You can uninstall the Valet daemon entirely by

              valet uninstall

Valet provides a blazing fast local development environment with minimal resource consumption, so it’s great for developers who only require PHP / MySQL and do not need a fully virtualized development environment.

Hope this blog has helped you in installing and using the Valet. We will come back with more interesting and useful blog next time keep watching for updates.

Anandhan S,
PHP Development Team,
Mallow Technologies.

Leave a Comment

Your email address will not be published. Required fields are marked *