Laravel Valet
Introduction
Looking for an even easier way to develop Laravel applications on macOS or Windows? Check out Laravel Herd. Herd includes everything you need to get started with Laravel development, including Valet, PHP, and Composer.
Laravel Valet is a development environment for macOS minimalists. Laravel Valet configures your Mac to always run Nginx in the background when your machine starts. Then, using DnsMasq, Valet proxies all requests on the *.test
domain to point to sites installed on your local machine.
In other words, Valet is a blazing fast Laravel development environment that uses roughly 7 MB of RAM. Valet isn't a complete replacement for Sail 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.
Out of the box, Valet support includes, but is not limited to:
- Laravel
- Bedrock
- CakePHP 3
- ConcreteCMS
- Contao
- Craft
- Drupal
- ExpressionEngine
- Jigsaw
- Joomla
- Katana
- Kirby
- Magento
- OctoberCMS
- Sculpin
- Slim
- Statamic
- Static HTML
- Symfony
- WordPress
- Zend
However, you may extend Valet with your own custom drivers.
Installation
Valet requires macOS 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.
To get started, you first need to ensure that Homebrew is up to date using the update
command:
brew update
Next, you should use Homebrew to install PHP:
brew install php
After installing PHP, you are ready to install the Composer package manager. In addition, you should make sure the $HOME/.composer/vendor/bin
directory is in your system's "PATH". After Composer has been installed, you may install Laravel Valet as a global Composer package:
composer global require laravel/valet
Finally, you may execute Valet's install
command. This will configure and install Valet and DnsMasq. In addition, the daemons Valet depends on will be configured to launch when your system starts:
valet install
Once Valet is installed, try pinging any *.test
domain on your terminal using a command such as ping foobar.test
. If Valet is installed correctly you should see this domain responding on 127.0.0.1
.
Valet will automatically start its required services each time your machine boots.
PHP Versions
Instead of modifying your global PHP version, you can instruct Valet to use per-site PHP versions via the isolate
command.
Valet allows you to switch PHP versions using the valet use php@version
command. Valet will install the specified PHP version via Homebrew if it is not already installed:
valet use php@8.2
valet use php
You may also create a .valetrc
file in the root of your project. The .valetrc
file should contain the PHP version the site should use:
php=php@8.2
Once this file has been created, you may simply execute the valet use
command and the command will determine the site's preferred PHP version by reading the file.
Valet only serves one PHP version at a time, even if you have multiple PHP versions installed.
Database
If your application needs a database, check out DBngin, which provides a free, all-in-one database management tool that includes MySQL, PostgreSQL, and Redis. After DBngin has been installed, you can connect to your database at 127.0.0.1
using the root
username and an empty string for the password.
Resetting Your Installation
If you are having trouble getting your Valet installation to run properly, executing the composer global require laravel/valet
command followed by valet install
will reset your installation and can solve a variety of problems. In rare cases, it may be necessary to "hard reset" Valet by executing valet uninstall --force
followed by valet install
.
Upgrading Valet
You may update your Valet installation by executing the composer global require laravel/valet
command in your terminal. After upgrading, it is good practice to run the valet install
command so Valet can make additional upgrades to your configuration files if necessary.