Laravel Valet
Introduction
Valet is a Laravel development environment for Mac minimalists. No Vagrant, No Apache, No Nginx, No /etc/hosts file. You can even share your sites publicly using local tunnels. Yeah, we like it too.
Laravel Valet configures your Mac to always run PHP's built-in web server in the background when your machine starts. Then, using DnsMasq, Valet proxies all requests on the *.dev domain to point to sites installed on your local machine.
In other words, a blazing fast Laravel development environment that uses roughly 7mb of RAM. Valet isn't a complete replacement for Vagrant or Homestead, but provides a great alternative if you want flexible basics, prefer extreme speed, or are working on a machine with a limited amount of RAM.
Valet supports Laravel, Lumen, and Statamic.
Installation
Valet requires the Mac operating system and Homebrew. Before installation, you should make sure that no other programs such as Apache or Nginx are binding to your local machine's port 80.
- Install or update Homebrew to the latest version.
- Make sure
brew servicesis available by runningbrew services listand making sure you get valid output. If it is not available, add it. - Install PHP 7.0 via Homebrew via
brew install php70. - Install Valet with Composer via
composer global require laravel/valet. Make sure the~/.composer/bindirectory is in your system's "PATH". - Run the
valet installcommand. This will configure and install Valet and DnsMasq, and register Valet's daemon to launch when your system starts.
Once Valet is installed, try pinging any *.dev domain on your terminal using a command such as ping foobar.dev. If Valet is installed correctly you should see this domain responding on 127.0.0.1.
Valet will automatically start its daemon each time your machine boots. There is no need to run valet start or valet install ever again once the initial Valet installation is complete.
Database
If you need a database, try MariaDB by running brew install mariadb on your command line. You can connect to the database at 127.0.0.1 using the root username and an empty string for the password.
Serving Sites
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.
- Create a new directory on your Mac by running something like
mkdir ~/Sites. Next,cd ~/Sitesand runvalet 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 this directory:
laravel new blog. - Open
http://blog.devin your browser.
That's all there is to it. Now, any Laravel project you create within your "parked" directory will automatically be served using the http://folder-name.dev convention.
The link command may also be used to serve your Laravel sites. This command is useful if you want to serve a single site in a directory and not the entire directory.
- To use the command, navigate to one of your projects and run
valet link app-namein your terminal. Valet will create a symbolic link in~/.valet/Siteswhich points to your current working directory. - After running the
linkcommand, you can access the site in your browser athttp://app-name.dev.
To see a listing of all of your linked directories, run the valet links command. You may use valet unlink app-name to destroy the symbolic link.
Sharing Sites
Valet even includes a command to share your local sites with the world. No additional software installation is required once Valet is installed.
To share a site, navigate to the site's directory in your terminal and run the valet share command. A publicly accessible URL will be inserted into your clipboard and is ready to paste directly into your browser. That's it.
To stop sharing your site, hit Control + C to cancel the process.
Viewing Logs
If you would like to stream all of the logs for all of your sites to your terminal, run the valet logs command. New log entries will display in your terminal as they occur. This is a great way to stay on top of all of your log files without ever having to leave your terminal.
Other Useful Commands
| Command | Description |
|---|---|
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. |