Laravel (5.7) Valet
Laravel Valet is a development environment that runs without Nginx and Apache.
It's a layer written upon the Caddy server to make setting up a Laravel environment easier.
Plus, it also employs DnsMasq to route requests to sites on your localhost so it takes the need to configure /etc/hosts and virtual hosts out of the equation.
Homestead andScotch Box are very popular options for setting up a Laravel development environment. Let's see how they compare to Valet.
Out of the box, Valet support includes, but is not limited to:
- CakePHP 3
- Static HTML
However, you may extend Valet with your own custom drivers.
Difference between Valet and Homestead
Similar to Homestead, Laravel offers Valet another local Laravel development environment. The difference between Homestead and Valet is seen in the environments they support. Valet only supports Mac, and requires you to install PHP and a database server directly onto your local machine. This is easily achieved by usingHomebrew with commands like brew install php and brew install mysql. Homebrew installsthe stuff you need that Apple (or your Linux system) didn’t. 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.
Installing the Pre-requisites
In order to install Valet, you should haveHomebrew,PHP 7, andComposer installed.
To install Homebrew, perform this operation in your terminal
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
The script will prompt you through the process so read and follow the steps carefully.
Installing PHP 7
Valet requires PHP's version 7.0 or greater.
In order to install PHP 7, execute the following command in your terminal.
$ brew install homebrew/php/php7.0
To check your current php version, run this command in your terminal
$ php -v
If the version you have is less than version 7, you will need to update your php version
You can check if you have Composer already installed on your local machine by executing the following command.
$ composer -v
If you do not have composer already installed, follow the next steps;
You can globally install Composer by following theinstructions at the official website.
When you are done, you should be able to access Composer from anywhere in your terminal.
You can verify if composer was successfully installed bu running
$ composer -v
If the output of the command shows the Composer version, it was set up correctly.
Also, make sure Composer's bin directory is added to your system PATH. You can do that by appending the following line at the end of your ~/.profile file.
If you're on Windows, make sure you have the path (C:\Users\<Username>\AppData\Roaming\Composer\vendor\bin) to composer in your environment variables.
export PATH="$PATH:$HOME/.composer/vendor/bin" # Add composer bin directory to PATH
Once you have Homebrew, PHP, and Composer installed, you can proceed to install Valet.
Before installing Valet, make sure there is no application installed and running that uses port 80. Generally, web servers such as Apache and Nginx use port 80 which will be required by Valet to run the Caddy server. If you have any service(or web server) configured to run on port 80, you should disable it.
Execute the following command to query any running services on port 80.
$ netstat -an | grep "\.80" | grep LISTEN
If the command produced empty output, port 80 is clean, and you are good to proceed with Valet installation.
Execute the following command to require Valet globally.
$ composer global require laravel/valet
Next, install Valet.
$ valet install
If Valet was installed correctly, you will be prompted with the Valet installed successfully! message.
Once Valet is installed, you're ready to start serving sites. Valet provides two commands to help you serve your Laravel sites: park and link.
$ valet park
This command will register your current working directory as a path that Valet should search for sites. Now, any Laravel project you create within your "parked" directory will automatically be served using the http://folder-name.dev convention.
Assuming you are working on a project “my-blog”, go into the directory and run the link command. For example,
$ cd ~/Projects/my-blog/
$ valet link awesome-blog
Valet will create a symbolic link in ~/.valet/Sites which points to your current working directory.
After running the link command, you can access the site in your browser at http://awesome-blog.dev.
To see a listing of all of your linked directories, run the valet links command. You may use valet unlink awesome-blog to destroy the symbolic link.
We have seen how you can set up local sites using the park and link commands.
Once you have set up a local site using either of these commands, you can create a sharing link that can be used to share your website with the world
Assuming you have linked the “my-blog” directory using the link command, here is how to create a sharing link.
$ cd ~/Projects/my-blog/
$ valet share
A new window will be initialized with a new process. Your site will be accessible as long as the process keeps running. You can terminate the process by pressing ctrl+C.
Other Valet Commands
valet forget - Run this command from a "parked" directory to remove it from the parked directory list.
valet paths - View all of your "parked" paths.
valet restart - Restart the Valet daemon. valet start Start the Valet daemon.
valet stop - Stop the Valet daemon. valet uninstall Uninstall the Valet daemon entirely.
- Exercises: Weekly Top 16 Most Popular Topics
- SQL Exercises, Practice, Solution - JOINS
- SQL Exercises, Practice, Solution - SUBQUERIES
- Java Array: Exercises, Practice, Solution
- C Programming Exercises, Practice, Solution : Conditional Statement
- HR Database - SORT FILTER: Exercises, Practice, Solution
- C Programming Exercises, Practice, Solution : String
- Python Data Types: Dictionary - Exercises, Practice, Solution
- Python Programming Puzzles - Exercises, Practice, Solution
- C++ Array: Exercises, Practice, Solution
- C# Sharp Basic Algorithm: Exercises, Practice, Solution
- Python Lambda - Exercises, Practice, Solution
- Python Pandas DataFrame: Exercises, Practice, Solution
- Conversion Tools